ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-06-03 09:55:28
Exec Total Coverage
Lines: 3083 8673 35.5%
Functions: 80 300 26.7%
Branches: 2697 7676 35.1%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "base/md5.h"
33 #include "hero_tiles.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include "iter.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern uint8_t ViewLayer3BG, ViewLayer2BG;
59 extern int32_t LayerDitherBG, LayerDitherSz;
60 extern bool NoHighlightLayer0;
61
62 using std::string;
63 using std::pair;
64
65 #define COLOR_SOLID vc(4)
66 #define COLOR_SLOPE vc(13)
67 #define COLOR_LADDER vc(6)
68 //#define COLOR_EFFECT vc(10)
69
70 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
71 extern char msgbuf[MSG_NEW_SIZE*8];
72
73 extern string zScript;
74
75 12 zmap Map;
76 int32_t prv_mode=0;
77
78 bool save_warn=true;
79
80 int32_t COMBOPOS(int32_t x, int32_t y)
81 {
82 return (((y) & 0xF0) + ((x) >> 4));
83 }
84 int32_t COMBOPOS_B(int32_t x, int32_t y)
85 {
86 if(unsigned(x) >= 256 || unsigned(y) >= 176)
87 return -1;
88 return COMBOPOS(x,y);
89 }
90 int32_t COMBOX(int32_t pos)
91 {
92 return ((pos) % 16 * 16);
93 }
94 int32_t COMBOY(int32_t pos)
95 {
96 return ((pos) & 0xF0);
97 }
98
99 void reset_dmap(int32_t index)
100 {
101 bound(index,0,MAXDMAPS-1);
102 DMaps[index].clear();
103 DMaps[index].title = "";
104 sprintf(DMaps[index].intro, " ");
105 }
106
107 void reset_dmaps()
108 {
109 for(int32_t i=0; i<MAXDMAPS; i++)
110 reset_dmap(i);
111 }
112
113 void truncate_dmap_title(std::string& title)
114 {
115 title.resize(21, ' ');
116 }
117
118 mapscr* zmap::get_prvscr()
119 {
120 return &prvscr;
121 }
122
123
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 zmap::zmap()
124 {
125 23 can_paste=false;
126 23 prv_cmbcycle=0;
127 23 prv_advance=0;
128 23 prv_freeze=0;
129 23 copyffc=-1;
130
131 23 memset(scrpos, 0, sizeof(scrpos));
132 23 memset(scrview, 0, sizeof(scrview));
133 23 screens=NULL;
134 23 prv_time=0;
135 23 prv_scr=0;
136 23 prv_map=0;
137 23 copyscr=0;
138 23 cursor={};
139 copymap=0;
140 layer_target_map = 0;
141 layer_target_scr = 0;
142 layer_target_multiple = 0;
143 }
144
145 11 void zmap::clear()
146 {
147
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
148 11 }
149 void zmap::force_refr_pointer()
150 {
151 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
152 screens = nullptr;
153 else screens = &TheMaps[cursor.map*MAPSCRS];
154 }
155 bool zmap::CanUndo()
156 {
157 return undo_stack.size() > 0;
158 }
159 bool zmap::CanRedo()
160 {
161 return redo_stack.size() > 0;
162 }
163 bool zmap::CanPaste()
164 {
165 return can_paste;
166 }
167 int32_t zmap::CopyScr()
168 {
169 return (copymap<<8)+copyscr;
170 }
171 int32_t zmap::getCopyFFC()
172 {
173 return copyffc;
174 }
175 set_ffc_command::data_t zmap::getCopyFFCData()
176 {
177 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
178 }
179 67 int32_t zmap::getMapCount()
180 {
181 67 return map_count;
182 }
183 int32_t zmap::getLayerTargetMap()
184 {
185 return layer_target_map;
186 }
187 int32_t zmap::getLayerTargetScr()
188 {
189 return layer_target_scr;
190 }
191 int32_t zmap::getLayerTargetMultiple()
192 {
193 return layer_target_multiple;
194 }
195 bool zmap::isDungeon(int32_t scr)
196 {
197 for(int32_t i=0; i<4; i++)
198 {
199 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
200 {
201 return false;
202 }
203 }
204
205 return true;
206 }
207
208 bool zmap::clearall(bool validate)
209 {
210 Color=0;
211 char tbuf[10];
212
213 if((header.templatepath[0]!=0)&&validate)
214 {
215 if(!valid_zqt(header.templatepath))
216 {
217 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
218 return false;
219 }
220 }
221
222 for(int32_t i=0; i<map_count; i++)
223 {
224 setCurrMap(i);
225 sprintf(tbuf, "%d", i);
226 clearmap(true);
227 }
228
229 setCurrMap(0);
230 return true;
231 }
232
233 bool zmap::reset_templates(bool validate)
234 {
235 //why are we doing this?
236 if(colordata==NULL)
237 {
238 return false;
239 }
240
241 //int32_t ret;
242 word version, build, dummy, sversion=0;
243 byte dummyc;
244 word dummyw;
245 //int32_t section_size;
246 word temp_map_count;
247 mapscr temp_mapscr;
248 PACKFILE *f=NULL;
249
250 // setPackfilePassword(datapwd);
251 f=open_quest_template(&header, "modules/classic/default.qst", validate);
252 get_version_and_build(f, &version, &build);
253
254 if(!find_section(f, ID_MAPS))
255 {
256 // setPackfilePassword(NULL);
257 return false;
258 }
259
260 //section version info
261 if(!p_igetw(&sversion,f))
262 {
263 return false;
264 }
265
266 if(!p_igetw(&dummy,f))
267 {
268 return false;
269 }
270
271 //section size
272 dword dummy_size;
273 if(!p_igetl(&dummy_size,f))
274 {
275 return false;
276 }
277
278 //finally... section data
279 if(!p_igetw(&temp_map_count,f))
280 {
281 return false;
282 }
283
284 if(version>12)
285 {
286 if(!p_getc(&dummyc,f))
287 return qe_invalid;
288
289 if(!p_getc(&dummyc,f))
290 return qe_invalid;
291
292 if(!p_igetw(&dummyw,f))
293 return qe_invalid;
294
295 if(!p_igetw(&dummyw,f))
296 return qe_invalid;
297
298 if(!p_igetw(&dummyw,f))
299 return qe_invalid;
300
301 if(!p_igetw(&dummyw,f))
302 return qe_invalid;
303
304 if(!p_igetw(&dummyw,f))
305 return qe_invalid;
306
307 if(!p_igetw(&dummyw,f))
308 return qe_invalid;
309
310 if(!p_igetw(&dummyw,f))
311 return qe_invalid;
312
313 if(!p_igetw(&dummyw,f))
314 return qe_invalid;
315
316 if(!p_igetw(&dummyw,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_getc(&dummyc,f))
323 return qe_invalid;
324
325 if(!p_getc(&dummyc,f))
326 return qe_invalid;
327 }
328
329 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
330 {
331 readmapscreen(f, &header, &temp_mapscr, sversion);
332 }
333
334 readmapscreen(f, &header, &TheMaps[128], sversion);
335 readmapscreen(f, &header, &TheMaps[129], sversion);
336
337 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
338 {
339 readmapscreen(f, &header, &temp_mapscr, sversion);
340 }
341
342 if(version>12)
343 {
344 if(!p_getc(&dummyc,f))
345 return qe_invalid;
346
347 if(!p_getc(&dummyc,f))
348 return qe_invalid;
349
350 if(!p_igetw(&dummyw,f))
351 return qe_invalid;
352
353 if(!p_igetw(&dummyw,f))
354 return qe_invalid;
355
356 if(!p_igetw(&dummyw,f))
357 return qe_invalid;
358
359 if(!p_igetw(&dummyw,f))
360 return qe_invalid;
361
362 if(!p_igetw(&dummyw,f))
363 return qe_invalid;
364
365 if(!p_igetw(&dummyw,f))
366 return qe_invalid;
367
368 if(!p_igetw(&dummyw,f))
369 return qe_invalid;
370
371 if(!p_igetw(&dummyw,f))
372 return qe_invalid;
373
374 if(!p_igetw(&dummyw,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_getc(&dummyc,f))
381 return qe_invalid;
382
383 if(!p_getc(&dummyc,f))
384 return qe_invalid;
385 }
386
387 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
388 {
389 readmapscreen(f, &header, &temp_mapscr, sversion);
390 }
391
392 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
394
395 pack_fclose(f);
396 clear_quest_tmpfile();
397
398 return true;
399 }
400
401 bool zmap::clearmap(bool newquest)
402 {
403 if(cursor.map<map_count)
404 {
405 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
406 {
407 clearscr(i);
408 }
409
410 setCurrScr(0);
411
412 if(newquest)
413 {
414 if(!reset_templates(false))
415 {
416 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
417 }
418 }
419 }
420
421 return true;
422 }
423
424 MapCursor zmap::getCursor() const
425 {
426 return cursor;
427 }
428
429 void zmap::setCursor(MapCursor new_cursor)
430 {
431 if (cursor == new_cursor)
432 return;
433
434 optional<int> oldcolor;
435 if (screens)
436 oldcolor = getcolor();
437
438 cursor = new_cursor;
439
440 int newcolor = getcolor();
441 loadlvlpal(newcolor);
442 if (!oldcolor || *oldcolor != newcolor)
443 rebuild_trans_table();
444
445 reset_combo_animations2();
446 mmap_mark_dirty();
447 regions_mark_dirty();
448 refresh(rALL);
449 }
450
451 bool zmap::isValidPosition(ComboPosition pos) const
452 {
453 return pos.is_valid(cursor);
454 }
455
456 int zmap::getScreenForPosition(ComboPosition pos) const
457 {
458 return cursor.viewscr + pos.screen_offset();
459 }
460
461 mapscr* zmap::CurrScr()
462 {
463 return screens+cursor.screen;
464 }
465 mapscr* zmap::Scr(int32_t scr)
466 {
467 return screens+scr;
468 }
469 mapscr* zmap::Scr(ComboPosition pos)
470 {
471 if (!pos.is_valid(cursor))
472 return nullptr;
473
474 int screen_offset = pos.screen_offset();
475 int screen = cursor.viewscr + screen_offset;
476 return AbsoluteScr(cursor.map, screen);
477 }
478 mapscr* zmap::Scr(ComboPosition pos, int layer)
479 {
480 int map = cursor.map;
481 int screen = cursor.viewscr + pos.screen_offset();
482 if (layer)
483 {
484 mapscr* scr = Map.AbsoluteScr(map, screen);
485 map = scr->layermap[CurrentLayer-1]-1;
486 screen = scr->layerscreen[CurrentLayer-1];
487 }
488
489 return AbsoluteScr(map, screen);
490 }
491 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
492 {
493 mapscr* scr = Scr(pos, layer);
494 if (scr && !(scr->valid&mVALID))
495 {
496 scr->valid |= mVALID;
497 setcolor(Color, scr);
498 }
499 return scr;
500 }
501 mapscr* zmap::AbsoluteScr(int32_t scr)
502 {
503 if(unsigned(scr) >= MAPSCRS*getMapCount())
504 return nullptr;
505 return &TheMaps[scr];
506 }
507 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
508 {
509 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
510 return nullptr;
511 return AbsoluteScr((map*MAPSCRS)+scr);
512 }
513 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
514 {
515 mapscr* scr = AbsoluteScr(map, screen);
516 if (scr && !(scr->valid&mVALID))
517 {
518 scr->valid |= mVALID;
519 setcolor(Color, scr);
520 }
521 return scr;
522 }
523 void zmap::set_prvscr(int32_t map, int32_t scr)
524 {
525 prvscr=TheMaps[(map*MAPSCRS)+scr];
526
527 for(int32_t i=0; i<6; i++)
528 {
529 if(prvscr.layermap[i]>0)
530 {
531 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
532 }
533 else
534 prvlayers[i].valid = 0;
535 }
536
537 prv_map=map;
538 prv_scr=scr;
539 }
540 92 int32_t zmap::getCurrMap()
541 {
542 92 return cursor.map;
543 }
544 22 void zmap::regions_mark_dirty()
545 {
546 22 regions_dirty = true;
547 22 }
548 void zmap::regions_refresh()
549 {
550 if (!regions_dirty)
551 return;
552
553 regions_dirty = false;
554 region_descriptions.clear();
555
556 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
557 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
558 region_descriptions.clear();
559 }
560 const std::vector<region_description>& zmap::get_region_descriptions()
561 {
562 regions_refresh();
563 return region_descriptions;
564 }
565 bool zmap::is_region(int screen)
566 {
567 if (screen < 0 || screen >= 128)
568 return false;
569
570 regions_refresh();
571 return current_map_region_ids[screen];
572 }
573 bool zmap::isDark(int scr)
574 {
575 return (screens[scr].flags&fDARK)!=0;
576 }
577 bool zmap::isValid(int32_t scr)
578 {
579 return (screens[scr].valid&mVALID)!=0;
580 }
581 bool zmap::isValid(int32_t map, int32_t scr)
582 {
583 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
584 }
585
586 11 void zmap::setCurrMap(int32_t index)
587 {
588 11 optional<int> oldcolor;
589
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(screens)
590 oldcolor = getcolor();
591 11 scrpos[cursor.map] = cursor.screen;
592 11 scrview[cursor.map] = cursor.viewscr;
593 11 cursor.map = bound(index,0,map_count);
594 11 screens = &TheMaps[cursor.map*MAPSCRS];
595
596 11 cursor.viewscr = scrview[cursor.map];
597 11 cursor.setScreen(scrpos[cursor.map]);
598
599 11 int newcolor = getcolor();
600 11 loadlvlpal(newcolor);
601
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(!oldcolor || *oldcolor != newcolor)
602 11 rebuild_trans_table();
603
604 11 reset_combo_animations2();
605 11 mmap_mark_dirty();
606 11 regions_mark_dirty();
607 11 }
608
609 20 int32_t zmap::getCurrScr()
610 {
611 20 return cursor.screen;
612 }
613 11 void zmap::setCurrScr(int32_t scr)
614 {
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (scr == cursor.screen)
616 return;
617
618 11 int32_t oldcolor=getcolor();
619 11 cursor.setScreen(scr);
620
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!(screens[cursor.screen].valid&mVALID))
621 {
622 oldcolor=-1;
623 }
624
625 11 int32_t newcolor=getcolor();
626 11 loadlvlpal(newcolor);
627
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (newcolor!=oldcolor)
628 {
629 10 rebuild_trans_table();
630 10 }
631
632 11 reset_combo_animations2();
633 11 setlayertarget();
634 11 mmap_mark_dirty();
635 11 regions_mark_dirty();
636 11 }
637
638 int32_t zmap::getViewScr()
639 {
640 return cursor.viewscr;
641 }
642
643 11 void zmap::setViewSize(int32_t size)
644 {
645 11 cursor.setSize(size);
646 11 }
647
648 8 int32_t zmap::getViewSize()
649 {
650 8 return cursor.size;
651 }
652
653 11 void zmap::setlayertarget()
654 {
655 11 layer_target_map = 0;
656 11 layer_target_multiple = 0;
657
658
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
659 {
660
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
661 {
662 7616 int32_t i=(m*MAPSCRS+s);
663 7616 mapscr *ts=&TheMaps[i];
664
665 // Search through each layer
666
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
667 {
668
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45679 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
669 {
670 if(layer_target_map > 0)
671 {
672 layer_target_multiple += 1;
673 continue;
674 }
675
676 layer_target_map = m+1;
677 layer_target_scr = s;
678 }
679 45696 }
680 7616 }
681 56 }
682 11 }
683
684 void zmap::setcolor(int color, mapscr* scr)
685 {
686 if (!scr) scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 if(Color!=color)
691 {
692 Color = color;
693 loadlvlpal(color);
694 rebuild_trans_table();
695 }
696
697 mmap_mark_dirty();
698 }
699
700 33 int32_t zmap::getcolor()
701 {
702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(prv_mode)
703 {
704 return prvscr.color;
705 }
706
707 33 return screens[cursor.screen].color;
708 33 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 for(int q = 0; q < 6; ++q)
829 {
830 auto layer = map_autolayers[cursor.map*6+q];
831 screens[scr].layermap[q] = layer;
832 screens[scr].layerscreen[q] = layer ? scr : 0;
833 }
834 mmap_mark_dirty();
835 }
836
837 const char *loaderror[] =
838 {
839
840 "OK","File not found","Incomplete data",
841 "Invalid version","Invalid file"
842
843 };
844
845 int32_t zmap::load(const char *path)
846 {
847 PACKFILE *f=pack_fopen_password(path,F_READ, "");
848
849 if(!f)
850 return 1;
851
852
853 int16_t version;
854 byte build;
855
856 //get the version
857 if(!p_igetw(&version,f))
858 {
859 goto file_error;
860 }
861
862 //get the build
863 if(!p_getc(&build,f))
864 {
865 goto file_error;
866 }
867
868 for(int32_t i=0; i<MAPSCRS; i++)
869 {
870 mapscr tmpimportscr;
871 tmpimportscr.zero_memory();
872 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
873 {
874 al_trace("failed zmap::load\n");
875 goto file_error;
876 }
877
878 switch(ImportMapBias)
879 {
880 case 0:
881 *(screens+i) = tmpimportscr;
882 break;
883
884 case 1:
885 if(!(screens[i].valid&mVALID))
886 {
887 *(screens+i) = tmpimportscr;
888 }
889 break;
890
891 case 2:
892 if(tmpimportscr.valid&mVALID)
893 {
894 *(screens+i) = tmpimportscr;
895 }
896 break;
897 }
898 }
899
900
901 pack_fclose(f);
902
903 setCurrScr(0);
904 mmap_mark_dirty();
905 regions_mark_dirty();
906 return 0;
907
908 file_error:
909 pack_fclose(f);
910 clearmap(false);
911 return 2;
912 }
913
914 int32_t zmap::save(const char *path)
915 {
916 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
917
918 if(!f)
919 return 1;
920
921 if(!p_iputw(V_MAPS,f))
922 {
923 pack_fclose(f);
924 return 3;
925 }
926
927 // This was the "build number", but that's totally useless here. Keep this junk byte
928 // so as not to totally break exports between ZC versions.
929 if(!p_putc(0,f))
930 {
931 pack_fclose(f);
932 return 3;
933 }
934
935 for(int32_t i=0; i<MAPSCRS; i++)
936 {
937 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
938 {
939 pack_fclose(f);
940 return 2;
941 }
942 }
943
944 pack_fclose(f);
945 return 0;
946 }
947
948
949 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
950 {
951 // Hookshots can be blocked by solid combos on all 3 ground layers.
952 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
953
954 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
955 return true;
956 if (c->walk&(1<<i))
957 return false;
958
959 for(int32_t k=0; k<2; k++)
960 {
961 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
962
963 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
964 {
965 return false;
966 }
967 }
968
969 return true;
970 }
971
972 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
973 {
974 // Hookshots can be blocked by solid combos on all 3 ground layers.
975 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
976
977 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
978 return true;
979 if (c->walk&(1<<i))
980 return false;
981
982 for(int32_t k=0; k<2; k++)
983 {
984 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
985
986 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
987 {
988 return false;
989 }
990 }
991
992 return true;
993 }
994
995 bool zmap::isstepable(int32_t combo)
996 {
997 // This is kind of odd but it's true to the engine (see maps.cpp)
998 return (combo_class_buf[combobuf[combo].type].ladder_pass);
999 }
1000
1001 // Returns the letter of the warp combo.
1002 int32_t zmap::warpindex(int32_t combo)
1003 {
1004 switch(combobuf[combo].type)
1005 {
1006 case cCAVE:
1007 case cPIT:
1008 case cSTAIR:
1009 case cCAVE2:
1010 case cSWIMWARP:
1011 case cDIVEWARP:
1012 case cSWARPA:
1013 return 0;
1014
1015 case cCAVEB:
1016 case cPITB:
1017 case cSTAIRB:
1018 case cCAVE2B:
1019 case cSWIMWARPB:
1020 case cDIVEWARPB:
1021 case cSWARPB:
1022 return 1;
1023
1024 case cCAVEC:
1025 case cPITC:
1026 case cSTAIRC:
1027 case cCAVE2C:
1028 case cSWIMWARPC:
1029 case cDIVEWARPC:
1030 case cSWARPC:
1031 return 2;
1032
1033 case cCAVED:
1034 case cPITD:
1035 case cSTAIRD:
1036 case cCAVE2D:
1037 case cSWIMWARPD:
1038 case cDIVEWARPD:
1039 case cSWARPD:
1040 return 3;
1041
1042 case cPITR:
1043 case cSTAIRR:
1044 case cSWARPR:
1045 return 4;
1046 }
1047
1048 return -1;
1049
1050 }
1051
1052 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1053 {
1054 if(top)
1055 line(dest,x,y,x+15,y,c);
1056 rectfill(dest,x,y,x+3,y+15,c);
1057 rectfill(dest,x+12,y,x+15,y+15,c);
1058 rectfill(dest,x+4,y+2,x+11,y+5,c);
1059 rectfill(dest,x+4,y+10,x+11,y+13,c);
1060 }
1061
1062 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1063 {
1064 line(dest,x,y,x+15,y,c);
1065 }
1066
1067 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1068 {
1069 int32_t cx = COMBOX(pos);
1070 int32_t cy = COMBOY(pos);
1071
1072 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1073
1074 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1075
1076 int32_t bridgedetected = 0;
1077
1078 for(int32_t i=0; i<4; i++)
1079 {
1080 int32_t tx=((i&2)<<2)+x;
1081 int32_t ty=((i&1)<<3)+y;
1082 int32_t tx2=((i&2)<<2)+cx;
1083 int32_t ty2=((i&1)<<3)+cy;
1084 for (int32_t m = layer; m <= 1; m++)
1085 {
1086 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1087 {
1088 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1089 {
1090 bridgedetected |= (1<<i);
1091 }
1092 }
1093 else
1094 {
1095 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1096 {
1097 bridgedetected |= (1<<i);
1098 }
1099 }
1100 }
1101 if (bridgedetected & (1<<i))
1102 {
1103 if (i >= 3) break;
1104 else continue;
1105 }
1106 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1107 {
1108 for(int32_t k=0; k<8; k+=2)
1109 for(int32_t j=0; j<8; j+=2)
1110 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1111 }
1112 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1113 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1114
1115 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1116 {
1117 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1118 {
1119 for(int32_t k=0; k<8; k+=2)
1120 for(int32_t j=0; j<8; j+=2)
1121 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1122 }
1123 else
1124 {
1125 int32_t color = COLOR_SOLID;
1126
1127 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1128 color=vc(6);
1129 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1130 color=vc(7);
1131
1132 rectfill(dest,tx,ty,tx+7,ty+7,color);
1133 }
1134 }
1135 }
1136
1137 bridgedetected = 0;
1138 for(int32_t i=0; i<4; i++)
1139 {
1140 int32_t tx2=((i&2)<<2)+cx;
1141 int32_t ty2=((i&1)<<3)+cy;
1142 for (int32_t m = 0; m <= 1; m++)
1143 {
1144 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1145 {
1146 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1147 {
1148 bridgedetected |= (1<<i);
1149 }
1150 }
1151 else
1152 {
1153 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1154 {
1155 bridgedetected |= (1<<i);
1156 }
1157 }
1158 }
1159 }
1160
1161 // Draw damage combos
1162 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1163 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1164 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1165 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1166 || combo_class_buf[c1.type].modify_hp_amount
1167 || combo_class_buf[c2.type].modify_hp_amount;
1168
1169 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1170
1171 if(dmg)
1172 {
1173 if (bridgedetected <= 0)
1174 {
1175 for(int32_t k=0; k<16; k+=2)
1176 for(int32_t j=0; j<16; j+=2)
1177 if(((k+j)/2)%2)
1178 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1179 }
1180 else
1181 {
1182 for(int32_t i=0; i<4; i++)
1183 {
1184 if (!(bridgedetected & (1<<i)))
1185 {
1186 int32_t tx=((i&2)<<2)+x;
1187 int32_t ty=((i&1)<<3)+y;
1188 for(int32_t k=0; k<8; k+=2)
1189 for(int32_t j=0; j<8; j+=2)
1190 if(((k+j)/2)%2)
1191 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1192 }
1193 }
1194 }
1195 }
1196
1197 if(c.type == cSLOPE)
1198 {
1199 slope_info s(c, x, y);
1200 s.draw(dest, 0, 0, COLOR_SLOPE);
1201 }
1202 auto fl0 = MAPFLAG2(-1,cx,cy);
1203 auto fl1 = MAPFLAG2(0,cx,cy);
1204 auto fl2 = MAPFLAG2(1,cx,cy);
1205 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1206 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1207 {
1208 bool top = false;
1209 if(cy)
1210 {
1211 top = true;
1212 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1213 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1214 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1215 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1216 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1217 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1218 {
1219 top = false;
1220 }
1221 }
1222 draw_ladder(dest,x,y,COLOR_LADDER,top);
1223 }
1224 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1225 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1226 {
1227 draw_platform(dest,x,y,COLOR_LADDER);
1228 }
1229 }
1230
1231 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1232 {
1233 int32_t cx = COMBOX(pos);
1234 int32_t cy = COMBOY(pos);
1235
1236 if (screen < 0) return;
1237 if (map < 0) return;
1238
1239 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1240
1241 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1242
1243 int32_t bridgedetected = 0;
1244 for(int32_t i=0; i<4; i++)
1245 {
1246 int32_t tx=((i&2)<<2)+x;
1247 int32_t ty=((i&1)<<3)+y;
1248 int32_t tx2=((i&2)<<2)+cx;
1249 int32_t ty2=((i&1)<<3)+cy;
1250 for (int32_t m = layer; m <= 1; m++)
1251 {
1252 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1253 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1254 {
1255 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1256 {
1257 bridgedetected |= (1<<i);
1258 }
1259 }
1260 else
1261 {
1262 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1263 {
1264 bridgedetected |= (1<<i);
1265 }
1266 }
1267 }
1268 if (bridgedetected & (1<<i))
1269 {
1270 continue;
1271 }
1272 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1273 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1274
1275
1276 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1277 {
1278 for(int32_t k=0; k<8; k+=2)
1279 for(int32_t j=0; j<8; j+=2)
1280 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1281 }
1282 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1283 {
1284 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1285 {
1286 for(int32_t k=0; k<8; k+=2)
1287 for(int32_t j=0; j<8; j+=2)
1288 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1289 }
1290 else
1291 {
1292 int32_t color = COLOR_SOLID;
1293
1294 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1295 color=vc(6);
1296 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1297 color=vc(7);
1298
1299 rectfill(dest,tx,ty,tx+7,ty+7,color);
1300 }
1301 }
1302 }
1303
1304 bridgedetected = 0;
1305 for(int32_t i=0; i<4; i++)
1306 {
1307 int32_t tx2=((i&2)<<2)+cx;
1308 int32_t ty2=((i&1)<<3)+cy;
1309 for (int32_t m = 0; m <= 1; m++)
1310 {
1311 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1312 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1313 {
1314 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1315 {
1316 bridgedetected |= (1<<i);
1317 }
1318 }
1319 else
1320 {
1321 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1322 {
1323 bridgedetected |= (1<<i);
1324 }
1325 }
1326 }
1327 }
1328
1329 // Draw damage combos
1330 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1331 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1332 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1333 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1334 || combo_class_buf[c1.type].modify_hp_amount
1335 || combo_class_buf[c2.type].modify_hp_amount;
1336
1337 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1338
1339 if(dmg)
1340 {
1341 if (bridgedetected <= 0)
1342 {
1343 for(int32_t k=0; k<16; k+=2)
1344 for(int32_t j=0; j<16; j+=2)
1345 if(((k+j)/2)%2)
1346 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1347 }
1348 else
1349 {
1350 for(int32_t i=0; i<4; i++)
1351 {
1352 if (!(bridgedetected & (1<<i)))
1353 {
1354 int32_t tx=((i&2)<<2)+x;
1355 int32_t ty=((i&1)<<3)+y;
1356 for(int32_t k=0; k<8; k+=2)
1357 for(int32_t j=0; j<8; j+=2)
1358 if(((k+j)/2)%2)
1359 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1360 }
1361 }
1362 }
1363 }
1364
1365 if(c.type == cSLOPE)
1366 {
1367 slope_info s(c, x, y);
1368 s.draw(dest, 0, 0, COLOR_SLOPE);
1369 }
1370 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1371 auto fl1 = MAPFLAG3(map,screen,0,pos);
1372 auto fl2 = MAPFLAG3(map,screen,1,pos);
1373 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1374 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1375 {
1376 bool top = false;
1377 if(cy)
1378 {
1379 top = true;
1380 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1381 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1382 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1383 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1384 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1385 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1386 {
1387 top = false;
1388 }
1389 }
1390 draw_ladder(dest,x,y,COLOR_LADDER,top);
1391 }
1392 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1393 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1394 {
1395 draw_platform(dest,x,y,COLOR_LADDER);
1396 }
1397 }
1398
1399 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1400 {
1401 const newcombo& c = combobuf[cmbdat];
1402
1403 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1404
1405 for(int32_t i=0; i<4; i++)
1406 {
1407 int32_t tx=((i&2)<<2)+x;
1408 int32_t ty=((i&1)<<3)+y;
1409
1410 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1411 {
1412 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1413 {
1414 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1415 }
1416 else
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 }
1421
1422
1423 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1424 {
1425 for(int32_t k=0; k<8; k+=2)
1426 for(int32_t j=0; j<8; j+=2)
1427 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1428 }
1429 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1430 {
1431 if(c.type==cLADDERHOOKSHOT)
1432 {
1433 for(int32_t k=0; k<8; k+=2)
1434 for(int32_t j=0; j<8; j+=2)
1435 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1436 }
1437 else
1438 {
1439 int32_t color = COLOR_SOLID;
1440
1441 if(c.type==cLADDERONLY)
1442 color=vc(6);
1443 else if(c.type==cHOOKSHOTONLY)
1444 color=vc(7);
1445
1446 rectfill(dest,tx,ty,tx+7,ty+7,color);
1447 }
1448 }
1449
1450 // Draw damage combos
1451 if(combo_class_buf[c.type].modify_hp_amount != 0)
1452 {
1453 for(int32_t k=0; k<8; k+=2)
1454 for(int32_t j=0; j<8; j+=2)
1455 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1456 }
1457 }
1458
1459 if(c.type == cSLOPE)
1460 {
1461 slope_info s(c, 0, 0);
1462 zfix const& slope = s.slope();
1463
1464 BITMAP* sub = create_bitmap_ex(8,16,16);
1465 clear_bitmap(sub);
1466 s.draw(sub, 0, 0, COLOR_SLOPE);
1467 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1468 destroy_bitmap(sub);
1469 }
1470 if(c.flag == mfSIDEVIEWLADDER)
1471 {
1472 draw_ladder(dest,x,y,COLOR_LADDER);
1473 }
1474 else if(c.flag == mfSIDEVIEWPLATFORM)
1475 {
1476 draw_platform(dest,x,y,COLOR_LADDER);
1477 }
1478 }
1479
1480 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1481 {
1482 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1483 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1484 }
1485 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1486 {
1487
1488 newcombo const& c = combobuf[cmbdat];
1489
1490 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1491 {
1492 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1493 // text_mode(-1);
1494 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1495 if(sflag)
1496 {
1497 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1498 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1499 }
1500
1501 if(c.flag)
1502 {
1503 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1504 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1505 }
1506 }
1507
1508 if(flags&cCSET)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 // text_mode(inv?vc(15):vc(0));
1512 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1513 }
1514 else if(flags&cCTYPE)
1515 {
1516 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1517 // text_mode(inv?vc(15):vc(0));
1518 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1519 }
1520 }
1521
1522 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1523 {
1524 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1525
1526 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1527 if(repos)
1528 {
1529 combotile_override_x = x+(8*(scale-1));
1530 combotile_override_y = y+(8*(scale-1));
1531 }
1532 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1533 if(repos) combotile_override_x = combotile_override_y = -1;
1534 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1535 destroy_bitmap(b);
1536 }
1537 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1538 {
1539 static newcombo nilcombo;
1540 nilcombo.tile = 0;
1541
1542 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1543
1544 if(c.tile==0)
1545 {
1546 rectfill(dest,x,y,x+15,y+15,vc(0));
1547 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1548 return;
1549 }
1550
1551 putcombo(dest,x,y,cmbdat,cset);
1552
1553 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1554 {
1555 if(sflag)
1556 {
1557 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1558 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1559 }
1560
1561 if(combobuf[cmbdat].flag)
1562 {
1563 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1564 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1565 }
1566 }
1567
1568 if(flags&cWALK)
1569 {
1570 put_walkflags(dest,x,y,cmbdat,0);
1571 }
1572
1573 if(flags&cCSET)
1574 {
1575 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1576 // text_mode(inv?vc(15):vc(0));
1577 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1578 }
1579 else if(flags&cCTYPE)
1580 {
1581 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1582 // text_mode(inv?vc(15):vc(0));
1583 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1584 }
1585 }
1586 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1587 {
1588 auto blitx = 1 + (slot % 16) * 17;
1589 auto blity = 1 + (slot / 16) * 17;
1590 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1591 }
1592
1593
1594 void copy_mapscr(mapscr *dest, const mapscr *src)
1595 {
1596 if(!dest || !src) return;
1597 *dest = *src;
1598 }
1599
1600 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1601 {
1602 int32_t x=0,y=0;
1603 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1604
1605 switch(side)
1606 {
1607 case up:
1608 case down:
1609 x=((pos&15)<<4)+xofs;
1610 y=(ignorepos?0:(pos&0xF0))+yofs;
1611 break;
1612
1613 case left:
1614 case right:
1615 x=(ignorepos?0:((pos&15)<<4))+xofs;
1616 y=(pos&0xF0)+yofs;
1617 break;
1618 }
1619
1620 switch(type)
1621 {
1622 case dt_lock:
1623 case dt_shut:
1624 case dt_boss:
1625 case dt_bomb:
1626 switch(side)
1627 {
1628 case up:
1629 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1630 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1631 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1633 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1635 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1637 break;
1638
1639 case down:
1640 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1641 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1642 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1644 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1646 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1648 break;
1649
1650 case left:
1651 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1653 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1655 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1657
1658 if(x+16 >= dest->w)
1659 break;
1660
1661 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1663 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1665 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1667 break;
1668
1669 case right:
1670
1671 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1673 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1675 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1677
1678 if(x+16 <= 0)
1679 break;
1680
1681 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1682 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1683 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1684 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1685 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1686 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1687 break;
1688 }
1689
1690 break;
1691
1692 case dt_pass:
1693 case dt_wall:
1694 case dt_walk:
1695 default:
1696 break;
1697 }
1698 }
1699
1700 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1701 {
1702 int32_t x=((pos&15)<<4)+xofs;
1703 int32_t y=(pos&0xF0)+yofs;
1704 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1705
1706
1707 switch(side)
1708 {
1709 case up:
1710 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1711 {
1712 overcombo(dest,x,y,
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1714 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1715 }
1716
1717 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1718 {
1719 overcombo(dest,x+16,y,
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1721
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1723 }
1724
1725 break;
1726
1727 case down:
1728 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1729 {
1730 overcombo(dest,x,y,
1731 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1732 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1733 }
1734
1735 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1736 {
1737 overcombo(dest,x+16,y,
1738 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1740 }
1741
1742 break;
1743
1744 case left:
1745 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1746 {
1747 overcombo(dest,x,y,
1748 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1749 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1750 }
1751
1752 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1753 {
1754 overcombo(dest,x,y+16,
1755 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1756 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1757 }
1758
1759 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1760 {
1761 overcombo(dest,x,y+32,
1762 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1764 }
1765
1766 break;
1767
1768 case right:
1769 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1770 {
1771 overcombo(dest,x,y,
1772 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1773 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1774 }
1775
1776 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1777 {
1778 overcombo(dest,x,y+16,
1779
1780 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1781 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1782 }
1783
1784 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1785 {
1786 overcombo(dest,x,y+32,
1787 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1788 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1789 }
1790
1791 break;
1792 }
1793 }
1794
1795 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1796 {
1797 word cmbcheck1, cmbcheck2;
1798 newcombo combocheck1, combocheck2;
1799 combocheck1 = combobuf[0];
1800 combocheck2 = combobuf[0];
1801 combocheck1.walk = 0;
1802 combocheck2.walk = 0;
1803
1804 int32_t layermap, layerscreen;
1805
1806 switch(dir)
1807 {
1808 case up:
1809 {
1810 if(i>15) //not top row of combos
1811 {
1812 return false;
1813 }
1814
1815 if(screen<16) //top row of screens
1816 {
1817 return false;
1818
1819 }
1820
1821 //check main screen
1822 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1823 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1824 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1825 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1826
1827 //check layer 1
1828 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1829
1830 if(layermap>-1 && layermap<map_count)
1831 {
1832 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1833 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1834 if (combobuf[cmbcheck1].type == cBRIDGE)
1835 {
1836 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1837 {
1838 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1839 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1840 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1841 }
1842 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1843 }
1844 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1845 }
1846
1847 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1848
1849 if(layermap>-1 && layermap<map_count)
1850 {
1851 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1852 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1853 if (combobuf[cmbcheck2].type == cBRIDGE)
1854 {
1855 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1856 {
1857 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1858 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1859 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1860 }
1861 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1862 }
1863 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1864 }
1865
1866 //check layer 2
1867 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1868
1869 if(layermap>-1 && layermap<map_count)
1870 {
1871 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1872
1873 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1874 if (combobuf[cmbcheck2].type == cBRIDGE)
1875 {
1876 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1877 {
1878 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1879 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1880 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1881 }
1882 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1883 }
1884 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1885 }
1886
1887 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1888
1889 if(layermap>-1 && layermap<map_count)
1890 {
1891 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1892 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1893 if (combobuf[cmbcheck2].type == cBRIDGE)
1894 {
1895 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1896 {
1897 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1898 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1899 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1900 }
1901 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1902 }
1903 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1904 }
1905
1906 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1907 {
1908 return true;
1909 }
1910
1911 break;
1912 }
1913 case down:
1914 {
1915 if(i<160) //not bottom row of combos
1916 {
1917 return false;
1918 }
1919
1920 if(screen>111) //bottom row of screens
1921 {
1922 return false;
1923 }
1924
1925 //check main screen
1926 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1927 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1928 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1929 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1930
1931
1932 //check layer 1
1933 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1934
1935 if(layermap>-1 && layermap<map_count)
1936 {
1937 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1938 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1939 if (combobuf[cmbcheck1].type == cBRIDGE)
1940 {
1941 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1942 {
1943 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1944 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1945 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1946 }
1947 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1948 }
1949 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1950 }
1951
1952 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1953
1954 if(layermap>-1 && layermap<map_count)
1955 {
1956 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1957 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1958 if (combobuf[cmbcheck2].type == cBRIDGE)
1959 {
1960 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1961 {
1962 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1963 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1964 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1965 }
1966 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1967 }
1968 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1969 }
1970
1971 //check layer 2
1972 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1973
1974 if(layermap>-1 && layermap<map_count)
1975 {
1976 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1977 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1978 if (combobuf[cmbcheck1].type == cBRIDGE)
1979 {
1980 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1981 {
1982 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1983 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1984 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1985 }
1986 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1987 }
1988 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1989 }
1990
1991 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1992
1993 if(layermap>-1 && layermap<map_count)
1994 {
1995 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1996 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1997 if (combobuf[cmbcheck2].type == cBRIDGE)
1998 {
1999 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2000 {
2001 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2002 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2003 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2004 }
2005 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2006 }
2007 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2008 }
2009
2010 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2011 {
2012 return true;
2013 }
2014
2015 break;
2016 }
2017 case left:
2018 {
2019 if((i&0xF)!=0) //not left column of combos
2020 {
2021 return false;
2022 }
2023
2024 if((screen&0xF)==0) //left column of screens
2025 {
2026 return false;
2027 }
2028
2029 //check main screen
2030 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2031 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2032 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2033 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2034
2035 //check layer 1
2036 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2037
2038 if(layermap>-1 && layermap<map_count)
2039 {
2040 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2041 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2042 if (combobuf[cmbcheck1].type == cBRIDGE)
2043 {
2044 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2045 {
2046 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2047 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2048 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2049 }
2050 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2051 }
2052 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2053 }
2054
2055 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2056
2057 if(layermap>-1 && layermap<map_count)
2058 {
2059 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2060 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2061 if (combobuf[cmbcheck2].type == cBRIDGE)
2062 {
2063 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2064 {
2065 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2066 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2067 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2068 }
2069 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2070 }
2071 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2072 }
2073
2074 //check layer 2
2075 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2076
2077 if(layermap>-1 && layermap<map_count)
2078 {
2079 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2080 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2081 if (combobuf[cmbcheck1].type == cBRIDGE)
2082 {
2083 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2084 {
2085 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2086 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2087 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2088 }
2089 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2090 }
2091 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2092 }
2093
2094 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2095
2096 if(layermap>-1 && layermap<map_count)
2097 {
2098 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2099 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2100 if (combobuf[cmbcheck2].type == cBRIDGE)
2101 {
2102 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2103 {
2104 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2105 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2106 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2107 }
2108 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2109 }
2110 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2111 }
2112
2113 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2114 {
2115 return true;
2116 }
2117
2118 break;
2119 }
2120 case right:
2121 {
2122 if((i&0xF)!=15) //not right column of combos
2123 {
2124 return false;
2125 }
2126
2127 if((screen&0xF)==15) //right column of screens
2128 {
2129 return false;
2130 }
2131
2132 //check main screen
2133 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2134 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2135 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2136 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2137
2138 //check layer 1
2139 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2140
2141 if(layermap>-1 && layermap<map_count)
2142 {
2143 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2144 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2145 if (combobuf[cmbcheck1].type == cBRIDGE)
2146 {
2147 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2148 {
2149 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2150 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2151 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2152 }
2153 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2154 }
2155 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2156 }
2157
2158 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2159
2160 if(layermap>-1 && layermap<map_count)
2161 {
2162 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2163 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2164 if (combobuf[cmbcheck2].type == cBRIDGE)
2165 {
2166 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2167 {
2168 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2169 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2170 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2171 }
2172 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2173 }
2174 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2175 }
2176
2177 //check layer 2
2178 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2179
2180 if(layermap>-1 && layermap<map_count)
2181 {
2182 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2183 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2184 if (combobuf[cmbcheck1].type == cBRIDGE)
2185 {
2186 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2187 {
2188 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2189 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2190 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2191 }
2192 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2193 }
2194 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2195 }
2196
2197 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2198
2199 if(layermap>-1 && layermap<map_count)
2200 {
2201 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2202
2203 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2204 if (combobuf[cmbcheck2].type == cBRIDGE)
2205 {
2206 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2207 {
2208 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2209 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2210 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2211 }
2212 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2213 }
2214 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2215 }
2216
2217 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2218 {
2219 return true;
2220 }
2221
2222 break;
2223 }
2224 }
2225
2226 return false;
2227 }
2228
2229 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2230 {
2231 int32_t checkcombo;
2232
2233 if(alignment_arrow_timer>31)
2234 {
2235 if(scr<0)
2236 {
2237 scr=cursor.screen;
2238 }
2239
2240 if((scr<128)) //do the misalignment arrows
2241 {
2242 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2243 {
2244 if(misaligned(cursor.map, scr, checkcombo, up))
2245 {
2246 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2247 }
2248 }
2249
2250 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2251 {
2252 if(misaligned(cursor.map, scr, checkcombo, down))
2253 {
2254 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2255 }
2256 }
2257
2258 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2259 {
2260 if(misaligned(cursor.map, scr, checkcombo, left))
2261 {
2262 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2263 }
2264 }
2265
2266 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2267 {
2268 if(misaligned(cursor.map, scr, checkcombo, right))
2269 {
2270 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2271 }
2272 }
2273
2274 int32_t tempalign;
2275
2276 //check top left corner
2277 checkcombo=0;
2278 tempalign=0;
2279 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2280 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2281
2282 switch(tempalign)
2283 {
2284 case 0:
2285 break;
2286
2287 case 1: //up
2288 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2289 break;
2290
2291 case 2: //left
2292 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2293 break;
2294
2295 case 3: //up-left
2296 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2297 break;
2298 }
2299
2300 //check top right corner
2301 checkcombo=15;
2302 tempalign=0;
2303 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2304 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2305
2306 switch(tempalign)
2307 {
2308 case 0:
2309 break;
2310
2311 case 1: //up
2312 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2313 break;
2314
2315 case 2: //right
2316 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2317 break;
2318
2319 case 3: //up-right
2320 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2321 break;
2322 }
2323
2324 //check bottom left corner
2325 checkcombo=160;
2326 tempalign=0;
2327 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2328 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2329
2330 switch(tempalign)
2331 {
2332 case 0:
2333 break;
2334
2335 case 1: //down
2336 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2337 break;
2338
2339 case 2: //left
2340 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2341 break;
2342
2343 case 3: //down-left
2344 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2345 break;
2346 }
2347
2348 //check bottom right corner
2349
2350 checkcombo=175;
2351 tempalign=0;
2352 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2353 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2354
2355 switch(tempalign)
2356 {
2357 case 0:
2358 break;
2359
2360 case 1: //down
2361 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2362 break;
2363
2364 case 2: //right
2365 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2366 break;
2367
2368 case 3: //down-right
2369 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2370 break;
2371 }
2372 }
2373 }
2374 }
2375
2376 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2377 {
2378 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2379 }
2380
2381 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2382 {
2383 if (map < 0 || screen < 0) return 0;
2384
2385 if(pos>175 || pos < 0)
2386 return 0;
2387
2388 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2389
2390 if (!m->is_valid()) return 0;
2391
2392 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2393
2394 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2395
2396 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2397
2398 if (!scr->is_valid()) return 0;
2399
2400 return scr->data[pos]; // entire combo code
2401 }
2402
2403 // Takes array index layer num., not actual layer num.
2404 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2405 {
2406 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2407
2408 if(map<0)
2409 map=cursor.map;
2410
2411 if(scr<0)
2412 scr=cursor.screen;
2413
2414 mapscr *screen1;
2415
2416 if(prv_mode)
2417 {
2418 screen1=get_prvscr();
2419 }
2420 else
2421 {
2422 screen1=AbsoluteScr(cursor.map,cursor.screen);
2423 }
2424
2425 int32_t layermap;
2426 layermap=screen1->layermap[lyr]-1;
2427
2428 if(layermap<0 || layermap >= map_count) return 0;
2429
2430 mapscr *layer;
2431
2432 if(prv_mode)
2433 layer = &prvlayers[lyr];
2434 else
2435 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2436
2437 int32_t pos = COMBOPOS(x,y);
2438
2439 if(pos>175 || pos < 0)
2440 return 0;
2441
2442 return layer->data[pos];
2443 }
2444
2445 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2446 {
2447 if(map<0)
2448 map=cursor.map;
2449
2450 if(scr<0)
2451 scr=cursor.screen;
2452
2453 mapscr *screen1;
2454
2455 if(prv_mode)
2456 {
2457 screen1=get_prvscr();
2458 }
2459 else
2460 {
2461 screen1=AbsoluteScr(cursor.map,cursor.screen);
2462 }
2463
2464 x = vbound(x, 0, 16*16);
2465 y = vbound(y, 0, 11*16);
2466 int32_t combo = COMBOPOS(x,y);
2467
2468 if(combo>175 || combo < 0)
2469 return 0;
2470
2471 return screen1->data[combo];
2472 }
2473
2474 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2475 {
2476 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2477 }
2478
2479 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2480 {
2481 if (map < 0 || screen < 0) return 0;
2482
2483 if(pos>175 || pos < 0)
2484 return 0;
2485
2486 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2487
2488 if (!m->is_valid()) return 0;
2489
2490 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2491
2492 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2493
2494 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2495
2496 if (!scr->is_valid()) return 0;
2497
2498 return scr->sflag[pos]; // entire combo code
2499 }
2500
2501 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2502 {
2503 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2504
2505 if(map<0)
2506 map=cursor.map;
2507
2508 if(scr<0)
2509 scr=cursor.screen;
2510
2511 mapscr *screen1;
2512
2513 if(prv_mode)
2514 {
2515 screen1=get_prvscr();
2516 }
2517 else
2518 {
2519 screen1=AbsoluteScr(cursor.map,cursor.screen);
2520 }
2521
2522 int32_t layermap;
2523 layermap=screen1->layermap[lyr]-1;
2524
2525 if(layermap<0 || layermap >= map_count) return 0;
2526
2527 mapscr *layer;
2528
2529 if(prv_mode)
2530 layer = &prvlayers[lyr];
2531 else
2532 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2533
2534 int32_t combo = COMBOPOS(x,y);
2535
2536 if(combo>175 || combo < 0)
2537 return 0;
2538
2539 return layer->sflag[combo];
2540 }
2541
2542 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2543 {
2544 if(map<0)
2545 map=cursor.map;
2546
2547 if(scr<0)
2548 scr=cursor.screen;
2549
2550 mapscr *screen1;
2551
2552 if(prv_mode)
2553 {
2554 screen1=get_prvscr();
2555 }
2556 else
2557 {
2558 screen1=AbsoluteScr(cursor.map,cursor.screen);
2559 }
2560
2561 x = vbound(x, 0, 16*16);
2562 y = vbound(y, 0, 11*16);
2563 int32_t combo = COMBOPOS(x,y);
2564
2565 if(combo>175 || combo < 0)
2566 return 0;
2567
2568 return screen1->sflag[combo];
2569 }
2570
2571 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2572 {
2573 mapscr *layers[7];
2574 mapscr *basescr;
2575 if(prv_mode)
2576 {
2577 layers[0] = &prvscr;
2578 basescr = layers[0];
2579 for(auto q = 1; q < 7; ++q)
2580 {
2581 if(prvlayers[q-1].valid)
2582 layers[q] = &(prvlayers[q-1]);
2583 else layers[q] = NULL;
2584 }
2585 }
2586 else
2587 {
2588 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2589 basescr = layers[0];
2590 for(auto q = 1; q < 7; ++q)
2591 {
2592 int32_t lmap = basescr->layermap[q-1]-1;
2593 int32_t lscr = basescr->layerscreen[q-1];
2594 if(lmap < 0)
2595 layers[q] = NULL;
2596 else layers[q] = AbsoluteScr(lmap, lscr);
2597 }
2598 }
2599 for(auto q = 0; q < 7; ++q)
2600 {
2601 if(!layers[q]) continue;
2602 for(auto pos = 0; pos < 176; ++pos)
2603 {
2604 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2605 if(cmb.type == cTORCH)
2606 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2607 }
2608 }
2609 word maxffc = basescr->numFFC();
2610 for(auto q = 0; q < maxffc; ++q)
2611 {
2612 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2613 if(cmb.type == cTORCH)
2614 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2615 }
2616 }
2617
2618 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2619 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2620 {
2621 newcombo const& cmb = combobuf[cid];
2622 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2623 if(dither)
2624 {
2625 if (LayerDitherSz == 0)
2626 return;
2627 BITMAP* buf = create_bitmap_ex(8,16,16);
2628 clear_bitmap(buf);
2629 overcombo(buf,0,0,cid,cset);
2630 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2631 if(over)
2632 {
2633 if(transp)
2634 {
2635 color_map = &trans_table2;
2636 draw_trans_sprite(dest, buf, x, y);
2637 color_map = &trans_table;
2638 }
2639 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2640 }
2641 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2642 destroy_bitmap(buf);
2643 }
2644 else if(over)
2645 {
2646 if(transp)
2647 overcombotranslucent(dest,x,y,cid,cset,0);
2648 else overcombo(dest,x,y,cid,cset);
2649 }
2650 else put_combo(dest,x,y,cid,cset,flags,sflag);
2651 }
2652 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2653 {
2654 if(!md) return;
2655 for (int32_t i = 0; i < 176; i++)
2656 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2657 }
2658 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2659 {
2660 if(!md) return;
2661 for (int32_t i = 0; i < 176; i++)
2662 {
2663 int data = md->data[i];
2664 if(combo_class_buf[combobuf[data].type].overhead)
2665 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2666 }
2667 }
2668 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2669 {
2670 if(!LayerMaskInt[lyr])
2671 return nullptr;
2672 if(lyr == 0)
2673 return basescr;
2674 int layermap = basescr->layermap[lyr-1]-1;
2675
2676 if(layermap>-1 && layermap<map_count)
2677 {
2678 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2679 return &TheMaps[layerscreen];
2680 }
2681 return nullptr;
2682 }
2683 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2684 {
2685 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2686 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2687
2688 if(map<0)
2689 map=cursor.map;
2690
2691 if(screen<0)
2692 screen=cursor.screen;
2693
2694 mapscr *basescr;
2695 mapscr* layers[7] = {nullptr};
2696
2697 if(prv_mode)
2698 {
2699 hl_layer = -1;
2700 basescr=get_prvscr();
2701 }
2702 else
2703 {
2704 basescr=AbsoluteScr(map,screen);
2705 }
2706 layers[0] = _zmap_get_lyr_checked(0,basescr);
2707 for(int lyr = 1; lyr < 7; ++lyr)
2708 {
2709 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2710 : _zmap_get_lyr_checked(lyr,basescr);
2711 }
2712
2713 int32_t layermap, layerscreen;
2714 if(CurrentLayer < 1)
2715 layermap = -1;
2716 else
2717 layermap=basescr->layermap[CurrentLayer-1]-1;
2718
2719 if(!(basescr->valid&mVALID))
2720 {
2721 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2722 rectfill(dest,x,y,x+255,y+175,vc(1));
2723
2724 if(ShowMisalignments)
2725 {
2726 check_alignments(dest,x,y,screen);
2727 }
2728
2729 return;
2730 }
2731
2732 if(LayerMaskInt[0]==0)
2733 {
2734 byte bgfill = 0;
2735 if (LayerDitherBG > -1)
2736 bgfill = vc(LayerDitherBG);
2737 rectfill(dest,x,y,x+255,y+175,bgfill);
2738 }
2739
2740 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2741 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2742
2743 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2744 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2745
2746 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2747
2748 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2749
2750 int num_ffcs = basescr->numFFC();
2751 for(int32_t i=num_ffcs-1; i>=0; i--)
2752 {
2753 if(basescr->ffcs[i].data)
2754 {
2755 if(!(basescr->ffcs[i].flags&ffc_changer))
2756 {
2757 if(!(basescr->ffcs[i].flags&ffc_overlay))
2758 {
2759 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2760 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2761
2762 if(basescr->ffcs[i].flags&ffc_trans)
2763 {
2764 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2765 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2766 }
2767 else
2768 {
2769 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2770 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2771 }
2772 }
2773 }
2774 }
2775 }
2776
2777 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2778 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2779
2780 int32_t doortype[4];
2781
2782 for(int32_t i=0; i<4; i++)
2783 {
2784 switch(basescr->door[i])
2785 {
2786 case dOPEN:
2787 doortype[i]=dt_pass;
2788 break;
2789
2790 case dLOCKED:
2791 doortype[i]=dt_lock;
2792 break;
2793
2794 case d1WAYSHUTTER:
2795 case dSHUTTER:
2796 doortype[i]=dt_shut;
2797 break;
2798
2799 case dBOSS:
2800 doortype[i]=dt_boss;
2801 break;
2802
2803 case dBOMB:
2804 doortype[i]=dt_bomb;
2805 break;
2806 }
2807 }
2808
2809 switch(basescr->door[up])
2810 {
2811 case dBOMB:
2812 over_door(dest,39,up,x,y,false, screen);
2813 [[fallthrough]];
2814 case dOPEN:
2815 case dLOCKED:
2816 case d1WAYSHUTTER:
2817 case dSHUTTER:
2818 case dBOSS:
2819 put_door(dest,7,up,doortype[up],x,y,false,screen);
2820 break;
2821
2822 case dWALK:
2823 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2824 {
2825 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2826 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2827 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2828 }
2829 else
2830
2831 {
2832 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2833 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2834 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2835 }
2836
2837 break;
2838 }
2839
2840 switch(basescr->door[down])
2841 {
2842 case dBOMB:
2843 over_door(dest,135,down,x,y,false,screen);
2844 [[fallthrough]];
2845 case dOPEN:
2846 case dLOCKED:
2847 case d1WAYSHUTTER:
2848 case dSHUTTER:
2849 case dBOSS:
2850 put_door(dest,151,down,doortype[down],x,y,false,screen);
2851 break;
2852
2853 case dWALK:
2854 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2855 {
2856 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2857 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2858 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2859 }
2860 else
2861 {
2862 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2863 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2864 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2865 }
2866
2867 break;
2868 }
2869
2870 switch(basescr->door[left])
2871 {
2872 case dBOMB:
2873 over_door(dest,66,left,x,y,false,screen);
2874 [[fallthrough]];
2875 case dOPEN:
2876 case dLOCKED:
2877 case d1WAYSHUTTER:
2878 case dSHUTTER:
2879 case dBOSS:
2880 put_door(dest,64,left,doortype[left],x,y,false,screen);
2881 break;
2882
2883 case dWALK:
2884 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2885 {
2886 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2887 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2888 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2889 }
2890 else
2891 {
2892 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2893 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2894 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2895 }
2896
2897 break;
2898 }
2899
2900 switch(basescr->door[right])
2901 {
2902
2903 case dBOMB:
2904 over_door(dest,77,right,x,y,false,screen);
2905 [[fallthrough]];
2906 case dOPEN:
2907 case dLOCKED:
2908 case d1WAYSHUTTER:
2909 case dSHUTTER:
2910 case dBOSS:
2911 put_door(dest,78,right,doortype[right],x,y,false,screen);
2912 break;
2913
2914 case dWALK:
2915 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2916 {
2917 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2918 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2919 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2920 }
2921 else
2922 {
2923 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2924 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2925 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2926 }
2927
2928 break;
2929 }
2930
2931 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2932 {
2933 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2934 }
2935
2936 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2937 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2938 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2939
2940 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2941
2942 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2943 {
2944 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2945 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2946 }
2947 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2948
2949 for(int32_t i=num_ffcs-1; i>=0; i--)
2950 {
2951 if(basescr->ffcs[i].data)
2952 {
2953 if(!(basescr->ffcs[i].flags&ffc_changer))
2954 {
2955 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2956 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2957
2958 if(basescr->ffcs[i].flags&ffc_overlay)
2959 {
2960 if(basescr->ffcs[i].flags&ffc_trans)
2961 {
2962 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2963 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2964 }
2965 else
2966 {
2967 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2968 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2969 }
2970 }
2971 }
2972 }
2973 }
2974
2975 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2976
2977 for(int32_t i=num_ffcs-1; i>=0; i--)
2978 if(basescr->ffcs[i].data)
2979 if(basescr->ffcs[i].flags&ffc_changer)
2980 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2981
2982 if(flags&cWALK)
2983 {
2984 if(layers[0])
2985 for(int32_t i=0; i<176; i++)
2986 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2987
2988 for(int32_t k=0; k<2; k++)
2989 {
2990 if(layers[k+1])
2991 for(int32_t i=0; i<176; i++)
2992 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2993 }
2994 for(int32_t i=num_ffcs-1; i>=0; i--)
2995 {
2996 if(auto data = basescr->ffcs[i].data)
2997 {
2998 if(!(basescr->ffcs[i].flags&ffc_changer))
2999 {
3000 newcombo const& cmb = combobuf[data];
3001 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
3002 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
3003
3004 if(basescr->ffcs[i].flags&ffc_solid)
3005 {
3006 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
3007 }
3008
3009 if(cmb.type == cSLOPE)
3010 {
3011 slope_info s(cmb, tx, ty);
3012 s.draw(dest, 0, 0, COLOR_SLOPE);
3013 }
3014 }
3015 }
3016 }
3017 }
3018
3019 if(flags&cFLAGS)
3020 {
3021 if(LayerMaskInt[CurrentLayer]!=0)
3022 {
3023 for(int32_t i=0; i<176; i++)
3024 {
3025 if(CurrentLayer==0)
3026 {
3027 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3028 }
3029 else
3030 {
3031 if(prv_mode)
3032 {
3033 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3034 }
3035 else if(basescr->layermap[CurrentLayer-1] > 0)
3036 {
3037 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3038
3039 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3040 {
3041 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3042 TheMaps[_lscr].data[i],
3043 TheMaps[_lscr].cset[i], flags,
3044 TheMaps[_lscr].sflag[i]);
3045 }
3046 }
3047 }
3048 }
3049 }
3050 }
3051
3052 int32_t dark = basescr->flags&cDARK;
3053
3054 if(dark && !(flags&cNODARK)
3055 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3056 {
3057 for(int32_t j=0; j<80; j++)
3058 {
3059 for(int32_t i=0; i<(80)-j; i++)
3060 {
3061 if(((i^j)&1)==0)
3062 {
3063 putpixel(dest,x+i,y+j,vc(blackout_color));
3064 }
3065 }
3066 }
3067 }
3068
3069 if(ShowMisalignments)
3070 {
3071 check_alignments(dest,x,y,screen);
3072 }
3073 }
3074
3075 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3076 {
3077 if(map<0)
3078 map=cursor.map;
3079
3080 if(scr<0)
3081 scr=cursor.screen;
3082
3083 mapscr* layer=AbsoluteScr(map,scr);
3084 int32_t layermap=0, layerscreen=0;
3085
3086 if(!(layer->valid&mVALID))
3087 {
3088 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3089 rectfill(dest,x,y,x+255,y+15,vc(1));
3090 return;
3091 }
3092
3093 int32_t dark = layer->flags&4;
3094
3095 if(LayerMaskInt[0]==0)
3096 {
3097 rectfill(dest,x,y,x+255,y+15,0);
3098 }
3099
3100
3101 for(int32_t k=1; k<3; k++)
3102 {
3103 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3104 {
3105 layermap=layer->layermap[k]-1;
3106
3107 if(layermap>-1 && layermap<map_count)
3108 {
3109 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3110
3111 for(int32_t i=c; i<(c&0xF0)+16; i++)
3112 {
3113 auto data = TheMaps[layerscreen].data[i];
3114 auto cs = TheMaps[layerscreen].cset[i];
3115 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3116 }
3117 }
3118 }
3119 }
3120
3121 if(LayerMaskInt[0]!=0)
3122 {
3123 for(int32_t i=c; i<(c&0xF0)+16; i++)
3124 {
3125 word cmbdat = (i < 176 ? layer->data[i] : 0);
3126 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3127 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3128 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3129 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3130 }
3131 }
3132
3133 for(int32_t k=0; k<2; k++)
3134 {
3135 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3136 {
3137 layermap=layer->layermap[k]-1;
3138
3139 if(layermap>-1 && layermap<map_count)
3140 {
3141 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3142
3143 for(int32_t i=c; i<(c&0xF0)+16; i++)
3144 {
3145 auto data = TheMaps[layerscreen].data[i];
3146 auto cs = TheMaps[layerscreen].cset[i];
3147 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3148 }
3149 }
3150 }
3151 }
3152
3153 int32_t doortype[4];
3154
3155 for(int32_t i=0; i<4; i++)
3156 {
3157 switch(layer->door[i])
3158 {
3159 case dOPEN:
3160 doortype[i]=dt_pass;
3161 break;
3162
3163 case dLOCKED:
3164 doortype[i]=dt_lock;
3165 break;
3166
3167 case d1WAYSHUTTER:
3168 case dSHUTTER:
3169 doortype[i]=dt_shut;
3170 break;
3171
3172 case dBOSS:
3173 doortype[i]=dt_boss;
3174 break;
3175
3176 case dBOMB:
3177 doortype[i]=dt_bomb;
3178 break;
3179 }
3180 }
3181
3182 if(c<16)
3183 {
3184 switch(layer->door[up])
3185 {
3186 case dBOMB:
3187 case dOPEN:
3188 case dLOCKED:
3189 case d1WAYSHUTTER:
3190 case dSHUTTER:
3191 case dBOSS:
3192 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3193 break;
3194 }
3195 }
3196 else if(c>159)
3197 {
3198 switch(layer->door[down])
3199 {
3200 case dBOMB:
3201 case dOPEN:
3202 case dLOCKED:
3203 case d1WAYSHUTTER:
3204 case dSHUTTER:
3205 case dBOSS:
3206 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3207 break;
3208 }
3209 }
3210
3211 for(int32_t k=2; k<4; k++)
3212 {
3213 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3214 {
3215 layermap=layer->layermap[k]-1;
3216
3217 if(layermap>-1 && layermap<map_count)
3218 {
3219 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3220
3221 for(int32_t i=c; i<(c&0xF0)+16; i++)
3222 {
3223 if(layer->layeropacity[k]<255)
3224 {
3225 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3226 }
3227 else
3228 {
3229 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3230 }
3231 }
3232 }
3233 }
3234 }
3235
3236 //Overhead L0
3237 if(LayerMaskInt[0]!=0)
3238 {
3239 for(int32_t i=c; i<(c&0xF0)+16; i++)
3240 {
3241 int32_t ct1=layer->data[i];
3242 int32_t ct3=combobuf[ct1].type;
3243
3244 if(combo_class_buf[ct3].overhead)
3245 {
3246 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3247 }
3248 }
3249 }
3250
3251 //Overhead L1/2
3252 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3253 {
3254 for(int32_t k = 0; k < 2; ++k)
3255 {
3256 if(LayerMaskInt[k+1]!=0)
3257 {
3258 layermap=layer->layermap[k]-1;
3259
3260 if(layermap>-1 && layermap<map_count)
3261 {
3262 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3263 for(int32_t i=c; i<(c&0xF0)+16; i++)
3264 {
3265 auto data = TheMaps[layerscreen].data[i];
3266 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3267 auto cs = TheMaps[layerscreen].cset[i];
3268 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3269 }
3270 }
3271 }
3272 }
3273 }
3274
3275 for(int32_t k=4; k<6; k++)
3276 {
3277 if(LayerMaskInt[k+1]!=0)
3278 {
3279 layermap=layer->layermap[k]-1;
3280
3281 if(layermap>-1 && layermap<map_count)
3282 {
3283 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3284
3285 for(int32_t i=c; i<(c&0xF0)+16; i++)
3286 {
3287 auto data = TheMaps[layerscreen].data[i];
3288 auto cs = TheMaps[layerscreen].cset[i];
3289 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3290 }
3291 }
3292 }
3293 }
3294
3295 if(flags&cWALK)
3296 {
3297 if(LayerMaskInt[0]!=0)
3298 {
3299 for(int32_t i=c; i<(c&0xF0)+16; i++)
3300 {
3301 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3302 }
3303 }
3304
3305 for(int32_t k=0; k<2; k++)
3306 {
3307 if(LayerMaskInt[k+1]!=0)
3308 {
3309 for(int32_t i=c; i<(c&0xF0)+16; i++)
3310 {
3311 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3312 }
3313 }
3314 }
3315 }
3316
3317 if(flags&cFLAGS)
3318 {
3319 if(LayerMaskInt[CurrentLayer]!=0)
3320 {
3321 for(int32_t i=c; i<(c&0xF0)+16; i++)
3322 {
3323 if(CurrentLayer==0)
3324 {
3325 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3326 }
3327 else
3328 {
3329 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3330
3331 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3332 {
3333 if(i < 176)
3334 {
3335 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3336 TheMaps[_lscr].data[i],
3337 TheMaps[_lscr].cset[i], flags|dark,
3338 TheMaps[_lscr].sflag[i]);
3339 }
3340 else
3341 {
3342 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3343 }
3344 }
3345 }
3346 }
3347 }
3348
3349 /*
3350 if (LayerMaskInt[0]!=0) {
3351 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3352 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3353 }
3354 }
3355 */
3356 }
3357
3358 if(ShowMisalignments)
3359 {
3360 if(c<16)
3361 {
3362 check_alignments(dest,x,y,scr);
3363 }
3364 else if(c>159)
3365 {
3366 check_alignments(dest,x,y-160,scr);
3367 }
3368 }
3369 }
3370
3371 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3372 {
3373 if(map<0)
3374 map=cursor.map;
3375
3376 if(scr<0)
3377 scr=cursor.screen;
3378
3379 mapscr* layer=AbsoluteScr(map,scr);
3380 int32_t layermap=0, layerscreen=0;
3381
3382 if(!(layer->valid&mVALID))
3383 {
3384 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3385 rectfill(dest,x,y,x+15,y+175,vc(1));
3386 return;
3387 }
3388
3389 int32_t dark = layer->flags&4;
3390
3391 if(LayerMaskInt[0]==0)
3392 {
3393 rectfill(dest,x,y,x+15,y+175,0);
3394 }
3395
3396
3397 for(int32_t k=1; k<3; k++)
3398 {
3399 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3400 {
3401 layermap=layer->layermap[k]-1;
3402
3403 if(layermap>-1 && layermap<map_count)
3404 {
3405 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3406
3407 for(int32_t i=c; i<176; i+=16)
3408 {
3409 auto data = TheMaps[layerscreen].data[i];
3410 auto cs = TheMaps[layerscreen].cset[i];
3411 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3412 }
3413 }
3414 }
3415 }
3416
3417 if(LayerMaskInt[0]!=0)
3418 {
3419 for(int32_t i=c; i<176; i+=16)
3420 {
3421 word cmbdat = layer->data[i];
3422 byte cmbcset = layer->cset[i];
3423 int32_t cmbflag = layer->sflag[i];
3424 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3425 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3426 }
3427 }
3428
3429 for(int32_t k=0; k<2; k++)
3430 {
3431 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3432 {
3433 layermap=layer->layermap[k]-1;
3434
3435 if(layermap>-1 && layermap<map_count)
3436 {
3437 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3438
3439 for(int32_t i=c; i<176; i+=16)
3440 {
3441 auto data = TheMaps[layerscreen].data[i];
3442 auto cs = TheMaps[layerscreen].cset[i];
3443 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3444 }
3445 }
3446 }
3447 }
3448
3449 int32_t doortype[4];
3450
3451 for(int32_t i=0; i<4; i++)
3452 {
3453 switch(layer->door[i])
3454 {
3455 case dOPEN:
3456 doortype[i]=dt_pass;
3457 break;
3458
3459 case dLOCKED:
3460 doortype[i]=dt_lock;
3461 break;
3462
3463 case d1WAYSHUTTER:
3464 case dSHUTTER:
3465 doortype[i]=dt_shut;
3466 break;
3467
3468 case dBOSS:
3469 doortype[i]=dt_boss;
3470 break;
3471
3472 case dBOMB:
3473 doortype[i]=dt_bomb;
3474 break;
3475 }
3476 }
3477
3478 if((c&0x0F)==0)
3479 {
3480 switch(layer->door[left])
3481 {
3482
3483 case dBOMB:
3484 case dOPEN:
3485 case dLOCKED:
3486 case d1WAYSHUTTER:
3487 case dSHUTTER:
3488 case dBOSS:
3489 // put_door(dest,64,left,doortype[left],x+256,y,true);
3490 put_door(dest,64,left,doortype[left],x,y,true,scr);
3491 break;
3492 }
3493 }
3494 else if((c&0x0F)==15)
3495 {
3496 switch(layer->door[right])
3497 {
3498 case dBOMB:
3499 case dOPEN:
3500 case dLOCKED:
3501 case d1WAYSHUTTER:
3502 case dSHUTTER:
3503 case dBOSS:
3504 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3505 break;
3506 }
3507 }
3508
3509 for(int32_t k=2; k<4; k++)
3510 {
3511 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3512 {
3513 layermap=layer->layermap[k]-1;
3514
3515 if(layermap>-1 && layermap<map_count)
3516 {
3517 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3518
3519 for(int32_t i=c; i<176; i+=16)
3520 {
3521 auto data = TheMaps[layerscreen].data[i];
3522 auto cs = TheMaps[layerscreen].cset[i];
3523 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3524 }
3525 }
3526 }
3527 }
3528
3529 //Overhead L0
3530 if(LayerMaskInt[0]!=0)
3531 {
3532 for(int32_t i=c; i<176; i+=16)
3533 {
3534 auto data = TheMaps[layerscreen].data[i];
3535 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3536 auto cs = TheMaps[layerscreen].cset[i];
3537 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3538 }
3539 }
3540 //Overhead L1/2
3541 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3542 {
3543 for(int32_t k = 0; k < 2; ++k)
3544 {
3545 if(LayerMaskInt[k+1]!=0)
3546 {
3547 layermap=layer->layermap[k]-1;
3548
3549 if(layermap>-1 && layermap<map_count)
3550 {
3551 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3552 for(int32_t i=c; i<176; i+=16)
3553 {
3554 auto data = TheMaps[layerscreen].data[i];
3555 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3556 auto cs = TheMaps[layerscreen].cset[i];
3557 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3558 }
3559 }
3560 }
3561 }
3562 }
3563
3564
3565 for(int32_t k=4; k<6; k++)
3566 {
3567 if(LayerMaskInt[k+1]!=0)
3568 {
3569 layermap=layer->layermap[k]-1;
3570
3571 if(layermap>-1 && layermap<map_count)
3572 {
3573 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3574
3575 for(int32_t i=c; i<176; i+=16)
3576 {
3577 auto data = TheMaps[layerscreen].data[i];
3578 auto cs = TheMaps[layerscreen].cset[i];
3579 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3580 }
3581 }
3582 }
3583 }
3584
3585 if(flags&cWALK)
3586 {
3587 if(LayerMaskInt[0]!=0)
3588 {
3589 for(int32_t i=c&0xF; i<176; i+=16)
3590 {
3591 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3592 }
3593 }
3594
3595 for(int32_t k=0; k<2; k++)
3596 {
3597 if(LayerMaskInt[k+1]!=0)
3598 {
3599 for(int32_t i=c&0xF; i<176; i+=16)
3600 {
3601 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3602 }
3603 }
3604 }
3605 }
3606
3607 if(flags&cFLAGS)
3608 {
3609 if(LayerMaskInt[CurrentLayer]!=0)
3610 {
3611 for(int32_t i=c; i<176; i+=16)
3612 {
3613 if(CurrentLayer==0)
3614 {
3615 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3616 }
3617 else
3618 {
3619 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3620
3621 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3622 {
3623 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3624 TheMaps[_lscr].data[i],
3625 TheMaps[_lscr].cset[i], flags|dark,
3626 TheMaps[_lscr].sflag[i]);
3627 }
3628 }
3629 }
3630 }
3631 }
3632
3633 if(ShowMisalignments)
3634 {
3635 if((c&0x0F)==0)
3636 {
3637 check_alignments(dest,x,y,scr);
3638 }
3639 else if((c&0x0F)==15)
3640 {
3641 check_alignments(dest,x-240,y,scr);
3642 }
3643 }
3644 }
3645
3646 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3647 {
3648 if(map<0)
3649 map=cursor.map;
3650
3651 if(scr<0)
3652 scr=cursor.screen;
3653
3654 mapscr* layer=AbsoluteScr(map,scr);
3655 int32_t layermap=0, layerscreen=0;
3656
3657 if(!(layer->valid&mVALID))
3658 {
3659 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3660 rectfill(dest,x,y,x+15,y+15,vc(1));
3661 return;
3662 }
3663
3664 int32_t dark = layer->flags&4;
3665
3666 if(LayerMaskInt[0]!=0)
3667 {
3668 rectfill(dest,x,y,x+15,y+15,0);
3669 }
3670
3671 for(int32_t k=1; k<3; k++)
3672 {
3673 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3674 {
3675 layermap=layer->layermap[k]-1;
3676
3677 if(layermap>-1 && layermap<map_count)
3678 {
3679 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3680
3681 auto data = TheMaps[layerscreen].data[c];
3682 auto cs = TheMaps[layerscreen].cset[c];
3683 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3684 }
3685 }
3686 }
3687
3688 if(LayerMaskInt[0]!=0)
3689 {
3690 word cmbdat = layer->data[c];
3691 byte cmbcset = layer->cset[c];
3692 int32_t cmbflag = layer->sflag[c];
3693 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3694 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3695 }
3696
3697
3698 for(int32_t k=0; k<2; k++)
3699 {
3700 if(LayerMaskInt[k+1]!=0)
3701 {
3702 layermap=layer->layermap[k]-1;
3703
3704 if(layermap>-1 && layermap<map_count)
3705 {
3706 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3707
3708 auto data = TheMaps[layerscreen].data[c];
3709 auto cs = TheMaps[layerscreen].cset[c];
3710 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3711 }
3712 }
3713 }
3714
3715 for(int32_t k=2; k<4; k++)
3716 {
3717 if(LayerMaskInt[k+1]!=0)
3718 {
3719 layermap=layer->layermap[k]-1;
3720
3721 if(layermap>-1 && layermap<map_count)
3722 {
3723 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3724 auto data = TheMaps[layerscreen].data[c];
3725 auto cs = TheMaps[layerscreen].cset[c];
3726 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3727 }
3728 }
3729 }
3730
3731 //Overhead L0
3732 if(LayerMaskInt[0]!=0)
3733 {
3734 auto data = TheMaps[layerscreen].data[c];
3735 if(combo_class_buf[combobuf[data].type].overhead)
3736 {
3737 auto cs = TheMaps[layerscreen].cset[c];
3738 drawcombo(dest,x,y,data,cs,0,0);
3739 }
3740 }
3741 //Overhead L1/2
3742 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3743 {
3744 for(int32_t k = 0; k < 2; ++k)
3745 {
3746 if(LayerMaskInt[k+1]!=0)
3747 {
3748 layermap=layer->layermap[k]-1;
3749
3750 if(layermap>-1 && layermap<map_count)
3751 {
3752 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3753 auto data = TheMaps[layerscreen].data[c];
3754 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3755 auto cs = TheMaps[layerscreen].cset[c];
3756 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3757 }
3758 }
3759 }
3760 }
3761
3762
3763 for(int32_t k=4; k<6; k++)
3764 {
3765 if(LayerMaskInt[k+1]!=0)
3766 {
3767 layermap=layer->layermap[k]-1;
3768
3769 if(layermap>-1 && layermap<map_count)
3770 {
3771 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3772 auto data = TheMaps[layerscreen].data[c];
3773 auto cs = TheMaps[layerscreen].cset[c];
3774 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3775 }
3776 }
3777 }
3778
3779 if(flags&cWALK)
3780 {
3781 if(LayerMaskInt[0]!=0)
3782 {
3783 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3784 }
3785
3786 for(int32_t k=0; k<2; k++)
3787 {
3788 if(LayerMaskInt[k+1]!=0)
3789 {
3790 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3791 }
3792 }
3793 }
3794
3795 if(flags&cFLAGS)
3796 {
3797 if(LayerMaskInt[CurrentLayer]!=0)
3798 {
3799 int32_t i = c;
3800 //for(int32_t i=c; i==c; i++)
3801 {
3802 if(CurrentLayer==0)
3803 {
3804 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3805 }
3806 else
3807 {
3808 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3809
3810 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3811 {
3812 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3813 TheMaps[_lscr].data[i],
3814 TheMaps[_lscr].cset[i], flags|dark,
3815 TheMaps[_lscr].sflag[i]);
3816 }
3817 }
3818 }
3819 }
3820 }
3821
3822 if(ShowMisalignments)
3823 {
3824 switch(c)
3825 {
3826 case 0:
3827 check_alignments(dest,x,y,scr);
3828 break;
3829
3830 case 15:
3831 check_alignments(dest,x-240,y,scr);
3832 break;
3833
3834 case 160:
3835 check_alignments(dest,x,y-160,scr);
3836 break;
3837
3838 case 175:
3839 check_alignments(dest,x-240,y-160,scr);
3840 break;
3841 }
3842 }
3843 }
3844
3845 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3846 {
3847 if (InvalidBG == 2)
3848 {
3849 draw_checkerboard(dest, x, y, 16);
3850 }
3851 else if(InvalidBG == 1)
3852 {
3853 for(int32_t dy=0; dy<16; dy++)
3854 {
3855 for(int32_t dx=0; dx<16; dx++)
3856 {
3857 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3858 }
3859 }
3860 }
3861 else
3862 {
3863 rectfill(dest, x, y, x+15, y+15, vc(0));
3864 rect(dest, x, y, x+15, y+15, vc(15));
3865 line(dest, x, y, x+15, y+15, vc(15));
3866 line(dest, x, y+15, x+15, y, vc(15));
3867 }
3868 }
3869
3870 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3871 {
3872 if (InvalidBG == 2)
3873 {
3874 for(int32_t q = 0; q < 11; ++q)
3875 draw_checkerboard(dest, x, y + q * 16, 16);
3876 }
3877 else if(InvalidBG == 1)
3878 {
3879 for(int32_t dy=0; dy<176; dy++)
3880 {
3881 for(int32_t dx=0; dx<16; dx++)
3882 {
3883 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3884 }
3885 }
3886 }
3887 else
3888 {
3889 rectfill(dest, x, y, x+15, y+175, vc(0));
3890 rect(dest, x, y, x+15, y+175, vc(15));
3891 line(dest, x, y, x+15, y+175, vc(15));
3892 line(dest, x, y+175, x+15, y, vc(15));
3893 }
3894 }
3895
3896 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3897 {
3898 if (InvalidBG == 2)
3899 {
3900 for (int32_t q = 0; q < 16; ++q)
3901 draw_checkerboard(dest, x + q * 16, y, 16);
3902 }
3903 else if(InvalidBG == 1)
3904 {
3905 for(int32_t dy=0; dy<16; dy++)
3906 {
3907 for(int32_t dx=0; dx<256; dx++)
3908 {
3909 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3910 }
3911 }
3912 }
3913 else
3914 {
3915 rectfill(dest, x, y, x+255, y+15, vc(0));
3916 rect(dest, x, y, x+255, y+15, vc(15));
3917 line(dest, x, y, x+255, y+15, vc(15));
3918 line(dest, x, y+15, x+255, y, vc(15));
3919 }
3920 }
3921
3922 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3923 {
3924 for(int32_t i=0; i<176; i++)
3925 {
3926 word cmbdat = screens[TEMPLATE].data[i];
3927 byte cmbcset = screens[TEMPLATE].cset[i];
3928 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3929 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3930 }
3931 }
3932
3933 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3934 {
3935 for(int32_t i=0; i<176; i++)
3936 {
3937 word cmbdat = screens[TEMPLATE2].data[i];
3938 byte cmbcset = screens[TEMPLATE2].cset[i];
3939 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3940 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3941 }
3942 }
3943
3944 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3945 {
3946 word cmbdat = screens[TEMPLATE].data[pos];
3947 byte cmbcset = screens[TEMPLATE].cset[pos];
3948 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3949 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3950 }
3951
3952 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3953 {
3954 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3955 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3956 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3957 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3958 }
3959
3960 void zmap::scroll(int32_t dir, bool warp)
3961 {
3962 if(cursor.map<map_count)
3963 {
3964 switch(dir)
3965 {
3966 case up:
3967 if(warp && Map.CurrScr()->flags2&wfUP)
3968 {
3969 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3970 }
3971 else if(cursor.screen>15)
3972 {
3973 setCurrScr(cursor.screen - 16);
3974 }
3975
3976 break;
3977
3978 case down:
3979 if(warp && Map.CurrScr()->flags2&wfDOWN)
3980 {
3981 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3982 }
3983 else if(cursor.screen<MAPSCRS-16)
3984 {
3985 setCurrScr(cursor.screen + 16);
3986 }
3987
3988 break;
3989
3990 case left:
3991 if(warp && Map.CurrScr()->flags2&wfLEFT)
3992 {
3993 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3994 }
3995 else if(cursor.screen&15)
3996 {
3997 setCurrScr(cursor.screen - 1);
3998 }
3999
4000 break;
4001
4002 case right:
4003 if(warp && Map.CurrScr()->flags2&wfRIGHT)
4004 {
4005 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
4006 }
4007 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
4008 {
4009 setCurrScr(cursor.screen + 1);
4010 }
4011
4012 break;
4013 }
4014 }
4015 }
4016
4017 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4018 {
4019 switch(side)
4020 {
4021 case up:
4022 switch(door)
4023 {
4024 case dWALL:
4025 case dBOMB:
4026 case dWALK:
4027 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4028 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4029 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4030 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4031 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4032 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4033 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4034 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4035 break;
4036
4037 default:
4038 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4039 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4040 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4041 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4042 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4043 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4044 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4045 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4046 break;
4047 }
4048
4049 break;
4050
4051 case down:
4052 switch(door)
4053 {
4054 case dWALL:
4055 case dBOMB:
4056 case dWALK:
4057 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4058 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4059 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4060 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4061 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4062 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4063 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4064 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4065 break;
4066
4067 default:
4068 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4069 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4070 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4071 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4072 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4073 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4074 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4075 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4076 break;
4077 }
4078
4079 break;
4080
4081 case left:
4082 switch(door)
4083 {
4084 case dWALL:
4085 case dBOMB:
4086 case dWALK:
4087 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4088 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4089 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4090 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4091 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4092 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4093 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4094 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4095 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4096 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4097 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4098 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4099 break;
4100
4101 default:
4102 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4103 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4104 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4105 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4106 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4107 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4108 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4109 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4110 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4111 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4112 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4113 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4114 break;
4115 }
4116
4117 break;
4118
4119 case right:
4120 switch(door)
4121 {
4122 case dWALL:
4123 case dBOMB:
4124 case dWALK:
4125 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4126 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4127 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4128 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4129 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4130 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4131 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4132 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4133 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4134 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4135 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4136 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4137 break;
4138
4139 default:
4140 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4141 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4142 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4143 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4144 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4145 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4146 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4147 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4148 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4149 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4150 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4151 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4152 break;
4153 }
4154
4155 break;
4156 }
4157 }
4158 void zmap::DoPutDoorCommand(int side, int door, bool force)
4159 {
4160 if(!force && screens[cursor.screen].door[side] == door)
4161 return;
4162 bool already_list = InListCommand();
4163 if(!already_list)
4164 StartListCommand();
4165 DoSetDoorCommand(cursor.screen,side,door);
4166 if(door != dNONE)
4167 {
4168 word data[176] = {0};
4169 byte cset[176] = {0};
4170 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4171 for(int q = 0; q < 176; ++q)
4172 if(data[q])
4173 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4174 }
4175 if(!already_list)
4176 FinishListCommand();
4177 }
4178 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4179 {
4180 if(screens[screen].door[side] == door)
4181 return;
4182
4183 screens[screen].door[side] = door;
4184 if(door != dNONE)
4185 {
4186 word data[176] = {0};
4187 byte cset[176] = {0};
4188 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4189 for(int q = 0; q < 176; ++q)
4190 if(data[q])
4191 {
4192 screens[screen].data[q] = data[q];
4193 screens[screen].cset[q] = cset[q];
4194 }
4195 }
4196 }
4197
4198 void list_command::execute()
4199 {
4200 for (auto command : commands)
4201 {
4202 command->execute();
4203 }
4204 }
4205
4206 void list_command::undo()
4207 {
4208 for (int i = commands.size() - 1; i >= 0; i--)
4209 {
4210 commands[i]->undo();
4211 }
4212 }
4213
4214 int list_command::size()
4215 {
4216 int s = 0;
4217 for (auto command : commands)
4218 {
4219 s += command->size();
4220 }
4221 return s;
4222 }
4223
4224 void set_combo_command::execute()
4225 {
4226 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4227 if (!scr_ptr) return;
4228
4229 if (combo != -1) scr_ptr->data[pos] = combo;
4230 scr_ptr->cset[pos] = cset;
4231 }
4232
4233 void set_combo_command::undo()
4234 {
4235 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4236 if(!mapscr_ptr) return;
4237 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4238 mapscr_ptr->cset[pos] = prev_cset;
4239 }
4240
4241 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4242 {
4243 std::array<int, 8> initd_arr;
4244 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4245
4246 return {
4247 .x = ffc.x,
4248 .y = ffc.y,
4249 .vx = ffc.vx,
4250 .vy = ffc.vy,
4251 .ax = ffc.ax,
4252 .ay = ffc.ay,
4253 .data = ffc.data,
4254 .cset = ffc.cset,
4255 .delay = ffc.delay,
4256 .link = ffc.link,
4257 .script = ffc.script,
4258 .tw = ffc.txsz,
4259 .th = ffc.tysz,
4260 .ew = ffc.hit_width,
4261 .eh = ffc.hit_height,
4262 .flags = ffc.flags,
4263 .initd = initd_arr,
4264 .layer = ffc.layer
4265 };
4266 }
4267
4268 void set_ffc_command::execute()
4269 {
4270 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4271 if(!mapscr_ptr) return;
4272
4273 mapscr_ptr->valid |= mVALID;
4274 mapscr_ptr->ffcs[i].x = data.x;
4275 mapscr_ptr->ffcs[i].y = data.y;
4276 mapscr_ptr->ffcs[i].vx = data.vx;
4277 mapscr_ptr->ffcs[i].vy = data.vy;
4278 mapscr_ptr->ffcs[i].ax = data.ax;
4279 mapscr_ptr->ffcs[i].ay = data.ay;
4280 mapscr_ptr->ffcs[i].data = data.data;
4281 mapscr_ptr->ffcs[i].cset = data.cset;
4282 mapscr_ptr->ffcs[i].delay = data.delay;
4283 mapscr_ptr->ffcs[i].link = data.link;
4284 mapscr_ptr->ffcs[i].script = data.script;
4285 mapscr_ptr->ffcs[i].flags = data.flags;
4286 mapscr_ptr->ffEffectWidth(i, data.ew);
4287 mapscr_ptr->ffEffectHeight(i, data.eh);
4288 mapscr_ptr->ffTileWidth(i, data.tw);
4289 mapscr_ptr->ffTileHeight(i, data.th);
4290 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4291 mapscr_ptr->ffcs[i].layer = data.layer;
4292 mapscr_ptr->ffcCountMarkDirty();
4293 mapscr_ptr->ffcs[i].updateSolid();
4294 }
4295
4296 void set_ffc_command::undo()
4297 {
4298 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4299 if(!mapscr_ptr) return;
4300
4301 mapscr_ptr->ffcs[i].x = prev_data.x;
4302 mapscr_ptr->ffcs[i].y = prev_data.y;
4303 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4304 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4305 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4306 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4307 mapscr_ptr->ffcs[i].data = prev_data.data;
4308 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4309 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4310 mapscr_ptr->ffcs[i].link = prev_data.link;
4311 mapscr_ptr->ffcs[i].script = prev_data.script;
4312 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4313 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4314 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4315 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4316 mapscr_ptr->ffTileHeight(i, prev_data.th);
4317 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4318 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4319 mapscr_ptr->ffcCountMarkDirty();
4320 mapscr_ptr->ffcs[i].updateSolid();
4321 }
4322
4323 void set_flag_command::execute()
4324 {
4325 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4326 if(!mapscr_ptr) return;
4327
4328 mapscr_ptr->valid |= mVALID;
4329 mapscr_ptr->sflag[pos] = flag;
4330 }
4331
4332 void set_flag_command::undo()
4333 {
4334 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4335 if(!mapscr_ptr) return;
4336 mapscr_ptr->sflag[pos] = prev_flag;
4337 }
4338
4339 void set_door_command::execute()
4340 {
4341 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4342 if(!mapscr_ptr) return;
4343
4344 mapscr_ptr->valid |= mVALID;
4345 mapscr_ptr->door[side] = door;
4346 }
4347
4348 void set_door_command::undo()
4349 {
4350 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4351 }
4352
4353 void set_dcs_command::execute()
4354 {
4355 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4356 if(!mapscr_ptr) return;
4357
4358 mapscr_ptr->valid |= mVALID;
4359 mapscr_ptr->door_combo_set = dcs;
4360 }
4361
4362 void set_dcs_command::undo()
4363 {
4364 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4365 }
4366
4367 void paste_screen_command::execute()
4368 {
4369 perform(screen.get());
4370 }
4371
4372 void paste_screen_command::undo()
4373 {
4374 if (prev_screens.size() > 1)
4375 {
4376 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4377 ASSERT(prev_screens.size() == 128);
4378 for (int i = 0; i < 128; i++)
4379 {
4380 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4381 // TODO: why not just this?
4382 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4383 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4384 }
4385 return;
4386 }
4387
4388 perform(prev_screens[0].get());
4389 }
4390
4391 int paste_screen_command::size()
4392 {
4393 return prev_screens.size() + 1;
4394 }
4395
4396 void paste_screen_command::perform(mapscr* to)
4397 {
4398 if (to)
4399 {
4400 switch (type) {
4401 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4402 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4403 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4404 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4405 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4406 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4407 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4408 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4409 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4410 case ScreenPartial: Map.Paste(*to, screen_index); break;
4411 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4412 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4413 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4414 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4415 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4416 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4417 }
4418 }
4419 else
4420 {
4421 Map.clearscr(screen_index);
4422 }
4423 refresh(rALL);
4424 }
4425
4426 void set_screen_command::execute()
4427 {
4428 if (screen)
4429 {
4430 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4431 }
4432 else
4433 {
4434 Map.clearscr(screen_index);
4435 }
4436 refresh(rALL);
4437 }
4438
4439 void set_screen_command::undo()
4440 {
4441 if (prev_screen)
4442 {
4443 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4444 }
4445 else
4446 {
4447 Map.clearscr(screen_index);
4448 }
4449 refresh(rALL);
4450 }
4451
4452 int set_screen_command::size()
4453 {
4454 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4455 }
4456
4457 static std::shared_ptr<list_command> current_list_command;
4458 void zmap::StartListCommand()
4459 {
4460 ASSERT(!current_list_command);
4461 current_list_command.reset(new list_command);
4462 }
4463
4464 void zmap::FinishListCommand()
4465 {
4466 if (current_list_command->commands.size() == 1)
4467 {
4468 undo_stack.push_back(current_list_command->commands[0]);
4469 }
4470 else if (current_list_command->commands.size() > 1)
4471 {
4472 undo_stack.push_back(current_list_command);
4473 }
4474 CapCommandHistory();
4475 current_list_command = nullptr;
4476 }
4477
4478 void zmap::RevokeListCommand()
4479 {
4480 current_list_command->undo();
4481 current_list_command = nullptr;
4482 }
4483
4484 bool zmap::InListCommand() const
4485 {
4486 return current_list_command ? true : false;
4487 }
4488
4489 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4490 {
4491 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4492 if (!skip_execute) command->execute();
4493 if (current_list_command)
4494 {
4495 current_list_command->commands.push_back(command);
4496 if (current_list_command->commands.size() == 1)
4497 {
4498 current_list_command->cursor = command->cursor;
4499 }
4500 }
4501 else
4502 {
4503 undo_stack.push_back(command);
4504 CapCommandHistory();
4505 }
4506 saved = false;
4507 }
4508
4509 void zmap::UndoCommand()
4510 {
4511 if (undo_stack.size() <= 0) return;
4512
4513 // If not currently looking at the associated screen, first change the view
4514 // and wait for the next call to actually undo this command.
4515 auto command = undo_stack.back();
4516 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4517 {
4518 setCursor(command.get()->cursor);
4519 return;
4520 }
4521
4522 command->undo();
4523 redo_stack.push(command);
4524 undo_stack.pop_back();
4525 saved = false;
4526 }
4527
4528 void zmap::RedoCommand()
4529 {
4530 if (redo_stack.size() <= 0) return;
4531
4532 // If not currently selected the associated screen, first change the cursor
4533 // and wait for the next call to actually execute this command.
4534 auto command = redo_stack.top();
4535 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4536 {
4537 setCursor(command.get()->cursor);
4538 return;
4539 }
4540
4541 command->execute();
4542 undo_stack.push_back(command);
4543 redo_stack.pop();
4544 saved = false;
4545 }
4546
4547 11 void zmap::ClearCommandHistory()
4548 {
4549 11 current_list_command = nullptr;
4550 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4551 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4552 11 }
4553
4554 // Extra amount is from mapscr's vectors.
4555 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4556 // Allow the undo system to use roughly 100 MB of memory.
4557 // This doesn't count the memory used by commands that don't store a mapscr,
4558 // but that should be negligible.
4559 12 static int max_command_size = 100e6 / size_of_mapscr;
4560 void zmap::CapCommandHistory()
4561 {
4562 int size;
4563 do
4564 {
4565 size = 0;
4566 for (auto command : undo_stack)
4567 {
4568 size += command->size();
4569 }
4570 if (size > max_command_size) undo_stack.pop_front();
4571 } while (size > max_command_size);
4572 }
4573
4574 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4575 {
4576 if (!pos.is_valid(cursor))
4577 return;
4578
4579 int map = cursor.map;
4580 int screen = cursor.viewscr + pos.screen_offset();
4581 if (!AbsoluteScr(map, screen))
4582 return;
4583
4584 if (CurrentLayer)
4585 {
4586 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4587 map = scr->layermap[CurrentLayer-1]-1;
4588 screen = scr->layerscreen[CurrentLayer-1];
4589 }
4590 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4591 }
4592
4593 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4594 {
4595 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4596 if (!mapscr_ptr) return;
4597
4598 std::shared_ptr<set_combo_command> command(new set_combo_command);
4599 command->cursor = cursor;
4600 command->map = map;
4601 command->scr = scr;
4602 command->pos = pos;
4603 command->combo = combo;
4604 command->cset = cset;
4605 command->prev_combo = mapscr_ptr->data[pos];
4606 command->prev_cset = mapscr_ptr->cset[pos];
4607 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4608 {
4609 // nothing to do...
4610 return;
4611 }
4612
4613 ExecuteCommand(command);
4614 }
4615
4616 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4617 {
4618 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4619 if(!mapscr_ptr) return;
4620
4621 mapscr_ptr->ensureFFC(i);
4622
4623 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4624
4625 std::array<int, 8> initd_arr;
4626 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4627
4628 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4629
4630 command->cursor = cursor;
4631 command->map = map;
4632 command->scr = scr;
4633 command->i = i;
4634 command->data = data;
4635 command->prev_data = prev_data;
4636 if (data == prev_data)
4637 {
4638 // nothing to do...
4639 return;
4640 }
4641
4642 ExecuteCommand(command);
4643 }
4644
4645 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4646 {
4647 if (!pos.is_valid(cursor))
4648 return;
4649
4650 int map = cursor.map;
4651 int screen = cursor.viewscr + pos.screen_offset();
4652 if (!AbsoluteScr(map, screen))
4653 return;
4654
4655 if (CurrentLayer)
4656 {
4657 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4658 map = scr->layermap[CurrentLayer-1]-1;
4659 screen = scr->layerscreen[CurrentLayer-1];
4660 }
4661 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4662 }
4663
4664 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4665 {
4666 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4667 if(!mapscr_ptr) return;
4668
4669 std::shared_ptr<set_flag_command> command(new set_flag_command);
4670 command->cursor = cursor;
4671 command->map = map;
4672 command->scr = scr;
4673 command->pos = pos;
4674 command->flag = flag;
4675 command->prev_flag = mapscr_ptr->sflag[pos];
4676 if (command->flag == command->prev_flag)
4677 {
4678 // nothing to do...
4679 return;
4680 }
4681
4682 ExecuteCommand(command);
4683 }
4684
4685 void zmap::DoSetDoorCommand(int scr, int side, int door)
4686 {
4687 if(screens[scr].door[side] == door)
4688 return;
4689 std::shared_ptr<set_door_command> command(new set_door_command);
4690 command->cursor = cursor;
4691 command->side = side;
4692 command->door = door;
4693 command->prev_door = screens[scr].door[side];
4694
4695 ExecuteCommand(command);
4696 }
4697 void zmap::DoSetDCSCommand(int dcs)
4698 {
4699 if(screens[cursor.screen].door_combo_set == dcs)
4700 return;
4701 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4702 command->cursor = cursor;
4703 command->dcs = dcs;
4704 command->prev_dcs = screens[cursor.screen].door_combo_set;
4705
4706 ExecuteCommand(command);
4707 }
4708
4709 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4710 {
4711 if (screen == -1)
4712 screen = cursor.screen;
4713
4714 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4715 command->cursor = cursor;
4716 command->type = type;
4717 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4718 command->screen_index = screen;
4719
4720 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4721 {
4722 for (int i=0; i < 128; i++)
4723 {
4724 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4725 }
4726 }
4727 else
4728 {
4729 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4730 }
4731
4732 ExecuteCommand(command);
4733 }
4734
4735 void zmap::DoClearScreenCommand(int screen)
4736 {
4737 std::shared_ptr<set_screen_command> command(new set_screen_command);
4738 command->cursor = cursor;
4739 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4740 command->screen = std::shared_ptr<mapscr>(nullptr);
4741 command->screen_index = screen;
4742
4743 ExecuteCommand(command);
4744 }
4745
4746 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4747 {
4748 std::shared_ptr<set_screen_command> command(new set_screen_command);
4749 command->cursor = cursor;
4750 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4751 Template(floorcombo, floorcset, screen);
4752 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4753
4754 ExecuteCommand(command, true);
4755 }
4756
4757 void zmap::Copy(int scr)
4758 {
4759 if(screens[scr].valid&mVALID)
4760 {
4761 copy_mapscr(&copymapscr, &screens[scr]);
4762 //copymapscr=screens[scr];
4763 can_paste=true;
4764 copymap=cursor.map;
4765 copyscr=scr;
4766 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4767 copyffc = -1;
4768 }
4769 }
4770
4771 void zmap::CopyFFC(int32_t screen, int32_t n)
4772 {
4773 if(screens[screen].valid&mVALID)
4774 {
4775 copy_mapscr(&copymapscr, &screens[screen]);
4776 // Can't paste the screen itself
4777 can_paste = false;
4778 copymap=cursor.map;
4779 copyscr=screen;
4780 copyffc = n;
4781 }
4782 }
4783
4784 void zmap::Paste(const mapscr& copymapscr, int screen)
4785 {
4786 if(can_paste)
4787 {
4788 int32_t oldcolor=getcolor();
4789
4790 if(!(screens[screen].valid&mVALID))
4791 {
4792 screens[screen].valid |= mVALID;
4793 screens[screen].color = copymapscr.color;
4794 }
4795
4796 screens[screen].door_combo_set = copymapscr.door_combo_set;
4797
4798 for(int32_t i=0; i<4; i++)
4799 {
4800 screens[screen].door[i]=copymapscr.door[i];
4801 }
4802
4803 for(int32_t i=0; i<176; i++)
4804 {
4805 screens[screen].data[i] = copymapscr.data[i];
4806 screens[screen].cset[i] = copymapscr.cset[i];
4807 screens[screen].sflag[i] = copymapscr.sflag[i];
4808 }
4809
4810 int32_t newcolor=getcolor();
4811 loadlvlpal(newcolor);
4812
4813 if(newcolor!=oldcolor)
4814 {
4815 rebuild_trans_table();
4816 }
4817
4818 saved=false;
4819 }
4820 }
4821
4822 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4823 {
4824 if(can_paste)
4825 {
4826 screens[screen].undercombo = copymapscr.undercombo;
4827 screens[screen].undercset = copymapscr.undercset;
4828 saved=false;
4829 }
4830 }
4831
4832 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4833 {
4834 if(can_paste)
4835 {
4836 for(int32_t i=0; i<128; i++)
4837 {
4838 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4839 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4840 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4841 }
4842
4843 saved=false;
4844 }
4845 }
4846
4847 // TODO const mapscr& copymapscr
4848 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4849 {
4850 if(can_paste)
4851 {
4852 screens[screen].ffcs = copymapscr.ffcs;
4853 screens[screen].ffcCountMarkDirty();
4854 saved=false;
4855 }
4856 }
4857
4858 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4859 {
4860 if(can_paste)
4861 {
4862 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4863
4864 for(int32_t i=0; i<4; i++)
4865 {
4866 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4867 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4868 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4869 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4870 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4871 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4872 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4874 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4875 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4876 }
4877
4878 saved=false;
4879 }
4880 }
4881
4882 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4883 {
4884 if(can_paste)
4885 {
4886 screens[screen].csensitive = copymapscr.csensitive;
4887 screens[screen].oceansfx = copymapscr.oceansfx;
4888 screens[screen].bosssfx = copymapscr.bosssfx;
4889 screens[screen].secretsfx = copymapscr.secretsfx;
4890 screens[screen].holdupsfx = copymapscr.holdupsfx;
4891 screens[screen].flags = copymapscr.flags;
4892 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4893 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4894 screens[screen].flags3 = copymapscr.flags3;
4895 screens[screen].flags4 = copymapscr.flags4;
4896 screens[screen].flags5 = copymapscr.flags5;
4897 screens[screen].flags6 = copymapscr.flags6;
4898 screens[screen].flags7 = copymapscr.flags7;
4899 screens[screen].flags8 = copymapscr.flags8;
4900 screens[screen].flags9 = copymapscr.flags9;
4901 screens[screen].flags10 = copymapscr.flags10;
4902 screens[screen].flags11 = copymapscr.flags11;
4903 screens[screen].item = copymapscr.item;
4904 screens[screen].hasitem = copymapscr.hasitem;
4905 screens[screen].itemx = copymapscr.itemx;
4906 screens[screen].itemy = copymapscr.itemy;
4907 screens[screen].nextmap = copymapscr.nextmap;
4908 screens[screen].nextscr = copymapscr.nextscr;
4909 screens[screen].nocarry = copymapscr.nocarry;
4910 screens[screen].noreset = copymapscr.noreset;
4911 screens[screen].path[0] = copymapscr.path[0];
4912 screens[screen].path[1] = copymapscr.path[1];
4913 screens[screen].path[2] = copymapscr.path[2];
4914 screens[screen].path[3] = copymapscr.path[3];
4915 screens[screen].pattern = copymapscr.pattern;
4916 screens[screen].exitdir = copymapscr.exitdir;
4917 screens[screen].screen_midi = copymapscr.screen_midi;
4918 screens[screen].stairx = copymapscr.stairx;
4919 screens[screen].stairy = copymapscr.stairy;
4920 screens[screen].timedwarptics = copymapscr.timedwarptics;
4921 saved=false;
4922 }
4923 }
4924
4925 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4926 {
4927 if(can_paste)
4928 {
4929 screens[screen].warpreturnc = copymapscr.warpreturnc;
4930 screens[screen].warparrivalx = copymapscr.warparrivalx;
4931 screens[screen].warparrivaly = copymapscr.warparrivaly;
4932
4933 for(int32_t i=0; i<4; i++)
4934 {
4935 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4936 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4937 }
4938
4939 saved=false;
4940 }
4941 }
4942
4943 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4944 {
4945 if(can_paste)
4946 {
4947 for(int32_t i=0; i<4; i++)
4948 screens[screen].door[i] = copymapscr.door[i];
4949
4950 screens[screen].door_combo_set = copymapscr.door_combo_set;
4951 saved=false;
4952 }
4953 }
4954
4955 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4956 {
4957 if(can_paste)
4958 {
4959 for(int32_t i=0; i<6; i++)
4960 {
4961 screens[screen].layermap[i] = copymapscr.layermap[i];
4962 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4963 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4964 }
4965
4966 saved=false;
4967 }
4968 }
4969
4970 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4971 {
4972 if(can_paste)
4973 {
4974 screens[screen].room = copymapscr.room;
4975 screens[screen].catchall = copymapscr.catchall;
4976 saved=false;
4977 }
4978 }
4979
4980 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4981 {
4982 if(can_paste)
4983 {
4984 screens[screen].guy = copymapscr.guy;
4985 screens[screen].guytile = copymapscr.guytile;
4986 screens[screen].guycs = copymapscr.guycs;
4987 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4988 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4989 screens[screen].str = copymapscr.str;
4990 saved=false;
4991 }
4992 }
4993
4994 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4995 {
4996 if(can_paste)
4997 {
4998 int32_t oldcolor=getcolor();
4999 screens[screen].color = copymapscr.color;
5000 int32_t newcolor=getcolor();
5001 loadlvlpal(newcolor);
5002
5003 screens[screen].valid|=mVALID;
5004
5005 if(newcolor!=oldcolor)
5006 {
5007 rebuild_trans_table();
5008 }
5009
5010 saved=false;
5011 }
5012 }
5013
5014 void zmap::PasteAll(const mapscr& copymapscr, int screen)
5015 {
5016 if(can_paste)
5017 {
5018 int32_t oldcolor=getcolor();
5019 copy_mapscr(&screens[screen], &copymapscr);
5020 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
5021 //screens[screen]=copymapscr;
5022 int32_t newcolor=getcolor();
5023 loadlvlpal(newcolor);
5024
5025 screens[screen].valid|=mVALID;
5026
5027 if(newcolor!=oldcolor)
5028 {
5029 rebuild_trans_table();
5030 }
5031
5032 saved=false;
5033 }
5034 }
5035
5036
5037 void zmap::PasteToAll(const mapscr& copymapscr)
5038 {
5039 if(can_paste)
5040 {
5041 int32_t oldcolor=getcolor();
5042
5043 for(int32_t x=0; x<128; x++)
5044 {
5045 if(!(screens[x].valid&mVALID))
5046 {
5047 screens[x].valid |= mVALID;
5048 screens[x].color = copymapscr.color;
5049 }
5050
5051 for(int32_t i=0; i<176; i++)
5052 {
5053 screens[x].data[i] = copymapscr.data[i];
5054 screens[x].cset[i] = copymapscr.cset[i];
5055 screens[x].sflag[i] = copymapscr.sflag[i];
5056 }
5057 }
5058
5059 int32_t newcolor=getcolor();
5060 loadlvlpal(newcolor);
5061
5062 if(!(screens[cursor.screen].valid&mVALID))
5063 {
5064 newcolor=-1;
5065 }
5066
5067 if(newcolor!=oldcolor)
5068 {
5069 rebuild_trans_table();
5070 }
5071
5072 saved=false;
5073 }
5074 }
5075
5076 void zmap::PasteAllToAll(const mapscr& copymapscr)
5077 {
5078 if(can_paste)
5079 {
5080 int32_t oldcolor=getcolor();
5081
5082 for(int32_t x=0; x<128; x++)
5083 {
5084 copy_mapscr(&screens[x], &copymapscr);
5085 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5086 //screens[x]=copymapscr;
5087 }
5088
5089 int32_t newcolor=getcolor();
5090 loadlvlpal(newcolor);
5091
5092 if(!(screens[cursor.screen].valid&mVALID))
5093 {
5094 newcolor=-1;
5095 }
5096
5097 if(newcolor!=oldcolor)
5098 {
5099 rebuild_trans_table();
5100 }
5101
5102 saved=false;
5103 }
5104 }
5105
5106 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5107 {
5108 if(can_paste)
5109 {
5110 for(int32_t i=0; i<10; i++)
5111 screens[screen].enemy[i]=copymapscr.enemy[i];
5112 }
5113 }
5114
5115 void zmap::setCopyFFC(int32_t n)
5116 {
5117 copyffc = n;
5118 }
5119
5120 void zmap::update_combo_cycling()
5121 {
5122 if(!prv_mode||!prv_cmbcycle)
5123 {
5124 return;
5125 }
5126
5127 int32_t x;
5128 int32_t newdata[176];
5129 int32_t newcset[176];
5130 bool restartanim[MAXCOMBOS] = {0};
5131
5132 for(int32_t i=0; i<176; i++)
5133 {
5134 newdata[i]=-1;
5135 newcset[i]=-1;
5136
5137 x=prvscr.data[i];
5138
5139 //time to restart
5140 if((combobuf[x].aclk>=combobuf[x].speed) &&
5141 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5142 combobuf[x].can_cycle())
5143 {
5144 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5145 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5146
5147 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5148 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5149 int32_t c = newdata[i];
5150
5151 if(combobuf[c].animflags & AF_CYCLE)
5152 {
5153 restartanim[c]=true;
5154 }
5155 }
5156 }
5157
5158 for(int32_t i=0; i<176; i++)
5159 {
5160 x=prvscr.data[i];
5161
5162 //time to restart
5163 if((combobuf[x].aclk>=combobuf[x].speed) &&
5164 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5165 combobuf[x].can_cycle())
5166 {
5167 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5168 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5169
5170 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5171 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5172 int32_t c = newdata[i];
5173
5174 if(combobuf[c].animflags & AF_CYCLE)
5175 {
5176 restartanim[c]=true;
5177 }
5178 }
5179 }
5180
5181 for(int32_t i=0; i<176; i++)
5182 {
5183 if(newdata[i]==-1)
5184 continue;
5185
5186 prvscr.data[i]=newdata[i];
5187 prvscr.cset[i]=newcset[i];
5188 }
5189
5190 word maxffc = prvscr.numFFC();
5191 for(word i=0; i<maxffc; i++)
5192 {
5193 ffcdata& ffc = prvscr.ffcs[i];
5194 newcombo const& cmb = combobuf[ffc.data];
5195
5196 //time to restart
5197 if((cmb.aclk>=cmb.speed) &&
5198 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5199 cmb.can_cycle())
5200 {
5201 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5202 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5203
5204 if(!(cmb.animflags & AF_CYCLENOCSET))
5205 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5206
5207 if(combobuf[ffc.data].animflags & AF_CYCLE)
5208 {
5209 restartanim[ffc.data]=true;
5210 }
5211 prvscr.ffcs[i].data = ffc.data;
5212 prvscr.ffcs[i].cset=ffc.cset;
5213 }
5214 }
5215
5216
5217 if(get_qr(qr_CMBCYCLELAYERS))
5218 {
5219 for(int32_t j=0; j<6; j++)
5220 {
5221 if(!prvlayers[j].valid)
5222 continue;
5223
5224 for(int32_t i=0; i<176; i++)
5225 {
5226 newdata[i]=-1;
5227 newcset[i]=-1;
5228
5229 x=(prvlayers[j]).data[i];
5230
5231 //time to restart
5232 if((combobuf[x].aclk>=combobuf[x].speed) &&
5233 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5234 combobuf[x].can_cycle())
5235 {
5236 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5237 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5238
5239 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5240 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5241 int32_t c = newdata[i];
5242
5243 if(combobuf[c].animflags & AF_CYCLE)
5244 {
5245 restartanim[c]=true;
5246 }
5247 }
5248 }
5249
5250 for(int32_t i=0; i<176; i++)
5251 {
5252 x=(prvlayers[j]).data[i];
5253
5254 //time to restart
5255 if((combobuf[x].aclk>=combobuf[x].speed) &&
5256 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5257 combobuf[x].can_cycle())
5258 {
5259 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5260 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5261
5262 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5263 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5264 int32_t c = newdata[i];
5265
5266 if(combobuf[c].animflags & AF_CYCLE)
5267 {
5268 restartanim[c]=true;
5269 }
5270 }
5271 }
5272
5273 for(int32_t i=0; i<176; i++)
5274 {
5275 if(newdata[i]==-1)
5276 continue;
5277
5278 prvlayers[j].data[i]=newdata[i];
5279 prvlayers[j].cset[i]=newcset[i];
5280 }
5281 }
5282 }
5283
5284 for(int32_t i=0; i<MAXCOMBOS; i++)
5285 {
5286 if(restartanim[i])
5287 {
5288 combobuf[i].tile = combobuf[i].o_tile;
5289 combobuf[i].cur_frame=0;
5290 combobuf[i].aclk = 0;
5291 }
5292 }
5293 }
5294
5295 void zmap::update_freeform_combos()
5296 {
5297 if(!prv_mode||!prv_cmbcycle)
5298 {
5299 return;
5300 }
5301
5302 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5303 word maxffc = prvscr.numFFC();
5304 for(int32_t i=0; i<maxffc; i++)
5305 {
5306 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5307 {
5308 for(int32_t j=0; j<maxffc; j++)
5309 {
5310 if(i!=j)
5311 {
5312 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5313 {
5314 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5315 {
5316 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5317 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5318 {
5319 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5320 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5321 if(prvscr.ffcs[j].flags&ffc_changethis)
5322 {
5323 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5324 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5325 }
5326
5327 if(prvscr.ffcs[j].flags&ffc_changenext)
5328 prvscr.ffcs[i].data += 1;
5329
5330 if(prvscr.ffcs[j].flags&ffc_changeprev)
5331 prvscr.ffcs[i].data -= 1;
5332
5333 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5334 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5335 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5336
5337 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5338 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5339 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5340 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5341
5342 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5343 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5344 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5345 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5346 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5347
5348 if(prvscr.ffcs[i].flags&ffc_carryover)
5349 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5350 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5351
5352 prvscr.ffcs[i].flags&=~ffc_changer;
5353 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5354 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5355
5356 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5357 {
5358 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5359 }
5360
5361 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5362 {
5363 int32_t k=0;
5364
5365 if(prvscr.ffcs[j].flags&ffc_swapnext)
5366 k=j<(MAXFFCS-1)?j+1:0;
5367
5368 if(prvscr.ffcs[j].flags&ffc_swapprev)
5369 k=j>0?j-1:(MAXFFCS-1);
5370
5371 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5372 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5373 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5374 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5375 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5376 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5377 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5378 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5379 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5380 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5381 }
5382 }
5383 }
5384 }
5385 }
5386 }
5387
5388 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5389 {
5390 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5391 {
5392 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5393 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5394 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5395 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5396 }
5397 else
5398 {
5399 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5400 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5401 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5402 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5403 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5404 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5405
5406 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5407 {
5408 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5409
5410 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5411
5412 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5413
5414 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5415 }
5416 }
5417 }
5418 else
5419 {
5420 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5421 prvscr.ffcs[i].delay--;
5422 }
5423
5424 if(prvscr.ffcs[i].x<-32)
5425 {
5426 if(prvscr.flags6&fWRAPAROUNDFF)
5427 {
5428 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5429 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5430 }
5431 else
5432 {
5433 prvscr.ffcs[i].data = 0;
5434 prvscr.ffcs[i].flags&=~ffc_carryover;
5435 }
5436 }
5437
5438 if(prvscr.ffcs[i].y<-32)
5439 {
5440 if(prvscr.flags6&fWRAPAROUNDFF)
5441 {
5442 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5443 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5444 }
5445 else
5446 {
5447 prvscr.ffcs[i].data = 0;
5448 prvscr.ffcs[i].flags&=~ffc_carryover;
5449 }
5450 }
5451
5452 if(prvscr.ffcs[i].x>=288)
5453 {
5454 if(prvscr.flags6&fWRAPAROUNDFF)
5455 {
5456 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5457 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5458 }
5459 else
5460 {
5461 prvscr.ffcs[i].data = 0;
5462 prvscr.ffcs[i].flags&=~ffc_carryover;
5463 }
5464 }
5465
5466 if(prvscr.ffcs[i].y>=208)
5467 {
5468 if(prvscr.flags6&fWRAPAROUNDFF)
5469 {
5470 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5471 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5472 }
5473 else
5474 {
5475 prvscr.ffcs[i].data = 0;
5476 prvscr.ffcs[i].flags&=~ffc_carryover;
5477 }
5478 }
5479
5480 }
5481 }
5482 }
5483
5484 void zmap::goto_dmapscr(int dmap, int scr)
5485 {
5486 setCurrMap(DMaps[dmap].map);
5487 setCurrScr(scr+DMaps[dmap].xoff);
5488 }
5489 void zmap::goto_mapscr(int map, int scr)
5490 {
5491 setCurrMap(map);
5492 setCurrScr(scr);
5493 }
5494
5495 void zmap::dowarp(int32_t type, int32_t index)
5496 {
5497 set_warpback();
5498 if(type==0)
5499 {
5500
5501 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5502 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5503
5504 switch(screens[cursor.screen].tilewarptype[index])
5505 {
5506 case wtCAVE:
5507 case wtNOWARP:
5508 break;
5509
5510 default:
5511 goto_dmapscr(dmap, scr);
5512 break;
5513 }
5514 }
5515 else if(type==1)
5516 {
5517 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5518 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5519
5520 switch(screens[cursor.screen].sidewarptype[index])
5521 {
5522 case wtCAVE:
5523 case wtNOWARP:
5524 break;
5525
5526 default:
5527 goto_dmapscr(dmap, scr);
5528 break;
5529 }
5530 }
5531 }
5532
5533 extern int32_t prv_twon;
5534
5535 void zmap::prv_dowarp(int32_t type, int32_t index)
5536 {
5537 if(type==0)
5538 {
5539
5540 int32_t dmap=prvscr.tilewarpdmap[index];
5541 int32_t scr=prvscr.tilewarpscr[index];
5542
5543 switch(prvscr.tilewarptype[index])
5544 {
5545 case wtCAVE:
5546 case wtNOWARP:
5547 break;
5548
5549 default:
5550 //setCurrMap(DMaps[dmap].map);
5551 //setCurrScr(scr+DMaps[dmap].xoff);
5552 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5553 loadlvlpal(getcolor());
5554 rebuild_trans_table();
5555 //prv_cmbcycle=0;
5556 break;
5557 }
5558 }
5559 else if(type==1)
5560 {
5561 int32_t dmap=prvscr.sidewarpdmap[index];
5562 int32_t scr=prvscr.sidewarpscr[index];
5563
5564 switch(prvscr.sidewarptype[index])
5565 {
5566 case wtCAVE:
5567 case wtNOWARP:
5568 break;
5569
5570 default:
5571 //setCurrMap(DMaps[dmap].map);
5572 //setCurrScr(scr+DMaps[dmap].xoff);
5573 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5574 loadlvlpal(getcolor());
5575 rebuild_trans_table();
5576 //prv_cmbcycle=0;
5577 break;
5578 }
5579 }
5580
5581 if(prv_twon)
5582 {
5583 prv_time=get_prvscr()->timedwarptics;
5584 }
5585 }
5586
5587 void zmap::dowarp2(int32_t ring,int32_t index)
5588 {
5589 set_warpback();
5590 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5591 }
5592
5593 void zmap::set_warpback()
5594 {
5595 warpbackmap = cursor.map;
5596 warpbackscreen = cursor.screen;
5597 }
5598 bool zmap::has_warpback()
5599 {
5600 return warpbackmap && warpbackscreen
5601 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5602 }
5603 void zmap::warpback()
5604 {
5605 if(!has_warpback())
5606 return;
5607
5608 int m = cursor.map, s = cursor.screen;
5609 goto_mapscr(*warpbackmap, *warpbackscreen);
5610 warpbackmap = m;
5611 warpbackscreen = s;
5612 }
5613
5614 bool save_msgstrs(const char *path)
5615 {
5616 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5617
5618 if(!f)
5619 {
5620 return false;
5621 }
5622
5623 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5624 {
5625 pack_fclose(f);
5626 return true;
5627 }
5628
5629 pack_fclose(f);
5630 return false;
5631 }
5632
5633 1 bool save_strings_tsv(const char *path)
5634 {
5635 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5636
5637
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5638 {
5639 return false;
5640 }
5641
5642
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5643 {
5644 1 pack_fclose(f);
5645 1 return true;
5646 }
5647
5648 pack_fclose(f);
5649 return false;
5650 1 }
5651
5652 bool save_msgstrs_text(const char *path)
5653 {
5654 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5655
5656 if(!f)
5657 {
5658 return false;
5659 }
5660
5661 if(writestrings_text(f)==0)
5662 {
5663 pack_fclose(f);
5664 return true;
5665 }
5666
5667 pack_fclose(f);
5668 return false;
5669 }
5670
5671 bool load_msgstrs(const char *path, int32_t startstring)
5672 {
5673 //these are here to bypass compiler warnings about unused arguments
5674 startstring=startstring;
5675
5676 dword section_id;
5677 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5678
5679 if(!f)
5680 {
5681 return false;
5682 }
5683
5684 if(!p_mgetl(&section_id,f))
5685 {
5686 return false;
5687 }
5688
5689 if(section_id==ID_STRINGS)
5690 {
5691 if(readstrings(f, &header)==0)
5692 {
5693 pack_fclose(f);
5694 return true;
5695 }
5696 else
5697 {
5698 pack_fclose(f);
5699 return false;
5700 }
5701 }
5702
5703 pack_fclose(f);
5704 return false;
5705 }
5706
5707 bool load_strings_tsv(const char *path)
5708 {
5709 try
5710 {
5711 parse_strings_tsv(util::read_text_file(path));
5712 }
5713 catch (std::exception& ex)
5714 {
5715 InfoDialog("Import .tsv Error", ex.what()).show();
5716 return false;
5717 }
5718 return true;
5719 }
5720
5721 bool save_pals(const char *path)
5722 {
5723 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5724
5725 if(!f)
5726 {
5727 return false;
5728 }
5729
5730 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5731 {
5732 pack_fclose(f);
5733 return true;
5734 }
5735
5736 pack_fclose(f);
5737 return false;
5738 }
5739
5740 bool load_pals(const char *path, int32_t startcset)
5741 {
5742 dword section_id;
5743 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5744
5745 if(!f)
5746 {
5747 return false;
5748 }
5749
5750 if(!p_mgetl(&section_id,f))
5751 {
5752 return false;
5753 }
5754
5755 if(section_id==ID_CSETS)
5756 {
5757 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5758 {
5759 pack_fclose(f);
5760 loadlvlpal(Color);
5761 return true;
5762 }
5763 else
5764 {
5765 pack_fclose(f);
5766 return false;
5767 }
5768 }
5769
5770 return false;
5771 }
5772
5773 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5774 bool save_guys(const char *path)
5775 {
5776 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5777
5778 if(!f)
5779 {
5780 return false;
5781 }
5782
5783 /*
5784 int32_t id = ID_GUYS;
5785 if(!p_mputl(id,f))
5786 {
5787 return false;
5788 }
5789 */
5790
5791 zquestheader h;
5792 h.zelda_version = 0x250;
5793 h.build = 21;
5794
5795 if(writeguys(f, &h)==0)
5796 {
5797 pack_fclose(f);
5798 return true;
5799 }
5800
5801 pack_fclose(f);
5802 return false;
5803 }
5804
5805 bool load_guys(const char *path)
5806 {
5807 dword section_id;
5808 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5809
5810 if(!f)
5811 {
5812 return false;
5813 }
5814
5815 if(!p_mgetl(&section_id,f))
5816 {
5817 pack_fclose(f);
5818 return false;
5819 }
5820
5821 zquestheader h;
5822 h.zelda_version = 0x250;
5823 h.build = 21;
5824
5825 if(section_id==ID_GUYS)
5826 {
5827 if(readguys(f, &h)==0)
5828 {
5829 pack_fclose(f);
5830 return true;
5831 }
5832 }
5833
5834 pack_fclose(f);
5835 return false;
5836 }
5837
5838
5839 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5840 bool save_combo_alias(const char *path)
5841 {
5842 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5843
5844 if(!f)
5845 {
5846 return false;
5847 }
5848
5849 zquestheader h;
5850 h.zelda_version = 0x250;
5851 h.build = 21;
5852
5853 if(writecomboaliases(f, 0, 0)==0)
5854 {
5855 pack_fclose(f);
5856 return true;
5857 }
5858
5859 pack_fclose(f);
5860 return false;
5861 }
5862
5863 bool load_combo_alias(const char *path)
5864 {
5865 dword section_id;
5866 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5867
5868 if(!f)
5869 {
5870 return false;
5871 }
5872
5873 if(!p_mgetl(&section_id,f))
5874 {
5875 pack_fclose(f);
5876 return false;
5877 }
5878
5879 zquestheader h;
5880 h.zelda_version = 0x250;
5881 h.build = 21;
5882
5883 if(section_id==ID_COMBOALIASES)
5884 {
5885 if(readcomboaliases(f, &h, 0, 0)==0)
5886 {
5887 pack_fclose(f);
5888 return true;
5889 }
5890 }
5891
5892 pack_fclose(f);
5893 return false;
5894 }
5895
5896 bool load_zgp(const char *path)
5897 {
5898 dword section_id;
5899 word section_version;
5900 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5901
5902 if(!f)
5903 return false;
5904
5905 if(!p_mgetl(&section_id,f))
5906 {
5907 pack_fclose(f);
5908 return false;
5909 }
5910
5911 if(section_id!=ID_GRAPHICSPACK)
5912 {
5913 pack_fclose(f);
5914 return false;
5915 }
5916
5917 //section version info
5918 if(!p_igetw(&section_version,f))
5919 {
5920 return 2;
5921 }
5922
5923 if(!read_deprecated_section_cversion(f))
5924 {
5925 return 3;
5926 }
5927
5928 //tiles
5929 if(!p_mgetl(&section_id,f))
5930 {
5931 pack_fclose(f);
5932 return false;
5933 }
5934
5935 if(section_id==ID_TILES)
5936 {
5937 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5938 {
5939 pack_fclose(f);
5940 init_tiles(true, &header);
5941 return false;
5942 }
5943 }
5944 else
5945 {
5946 pack_fclose(f);
5947 return false;
5948 }
5949
5950 //combos
5951 if(!p_mgetl(&section_id,f))
5952 {
5953 pack_fclose(f);
5954 return false;
5955 }
5956
5957 if(section_id==ID_COMBOS)
5958 {
5959 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5960 {
5961 pack_fclose(f);
5962 return false;
5963 }
5964 }
5965 else
5966 {
5967 pack_fclose(f);
5968 return false;
5969 }
5970
5971 //palettes
5972 if(!p_mgetl(&section_id,f))
5973 {
5974 pack_fclose(f);
5975 return false;
5976 }
5977
5978 if(section_id==ID_CSETS)
5979 {
5980 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5981 {
5982 pack_fclose(f);
5983 return false;
5984 }
5985 }
5986 else
5987 {
5988 pack_fclose(f);
5989 return false;
5990 }
5991
5992 //items
5993 if(!p_mgetl(&section_id,f))
5994 {
5995 pack_fclose(f);
5996 return false;
5997 }
5998
5999 if(section_id==ID_ITEMS)
6000 {
6001 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6002 {
6003 pack_fclose(f);
6004 return false;
6005 }
6006 }
6007 else
6008 {
6009 pack_fclose(f);
6010 return false;
6011 }
6012
6013 //weapons
6014 if(!p_mgetl(&section_id,f))
6015 {
6016 pack_fclose(f);
6017 return false;
6018 }
6019
6020 if(section_id==ID_WEAPONS)
6021 {
6022 if(readweapons(f, &header)!=0)
6023 {
6024 pack_fclose(f);
6025 return false;
6026 }
6027 }
6028 else
6029 {
6030 pack_fclose(f);
6031 return false;
6032 }
6033
6034 //read the triforce pieces info and make sure it worked
6035 //really do this?
6036
6037 //read the game icons info and make sure it worked
6038 if(!p_mgetl(&section_id,f))
6039 {
6040 pack_fclose(f);
6041 return false;
6042 }
6043
6044 if(section_id==ID_ICONS)
6045 {
6046 if(readgameicons(f, &header, &QMisc)!=0)
6047 {
6048 pack_fclose(f);
6049 return false;
6050 }
6051 }
6052 else
6053 {
6054 pack_fclose(f);
6055 return false;
6056 }
6057
6058 //read the misc colors info and map styles info and make sure it worked
6059 if(!p_mgetl(&section_id,f))
6060 {
6061 pack_fclose(f);
6062 return false;
6063 }
6064
6065 if(section_id==ID_COLORS)
6066 {
6067 if(readmisccolors(f, &header, &QMisc)!=0)
6068 {
6069 pack_fclose(f);
6070 return false;
6071 }
6072 }
6073 else
6074 {
6075 pack_fclose(f);
6076 return false;
6077 }
6078
6079 //read the door combo sets and make sure it worked
6080 if(!p_mgetl(&section_id,f))
6081 {
6082 pack_fclose(f);
6083 return false;
6084 }
6085
6086 if(section_id==ID_DOORS)
6087 {
6088 if(readdoorcombosets(f, &header)!=0)
6089 {
6090 pack_fclose(f);
6091 return false;
6092 }
6093 }
6094 else
6095 {
6096 pack_fclose(f);
6097 return false;
6098 }
6099
6100 //read the template screens and make sure it worked
6101 //really do this?
6102
6103 //yay! it worked! close the file and say everything was ok.
6104 loadlvlpal(Color);
6105 setup_combo_animations();
6106 setup_combo_animations2();
6107 pack_fclose(f);
6108 return true;
6109 }
6110
6111 bool save_zgp(const char *path)
6112 {
6113 reset_combo_animations();
6114 reset_combo_animations2();
6115
6116 //open the file
6117 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6118
6119 if(!f)
6120 return false;
6121
6122 dword section_id=ID_GRAPHICSPACK;
6123 dword section_version=V_GRAPHICSPACK;
6124
6125 //section id
6126 if(!p_mputl(section_id,f))
6127 {
6128 return 1;
6129 }
6130
6131 //section version info
6132 if(!p_iputw(section_version,f))
6133 {
6134 return 2;
6135 }
6136
6137 if(!write_deprecated_section_cversion(section_version,f))
6138 {
6139 return 3;
6140 }
6141
6142 //tiles
6143 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6144 {
6145 pack_fclose(f);
6146 return false;
6147 }
6148
6149 //combos
6150 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6151 {
6152 pack_fclose(f);
6153 return false;
6154 }
6155
6156 //palettes
6157 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6158 {
6159 pack_fclose(f);
6160 return false;
6161 }
6162
6163 //items
6164 if(writeitems(f, &header)!=0)
6165 {
6166 pack_fclose(f);
6167 return false;
6168 }
6169
6170 //weapons
6171 if(writeweapons(f, &header)!=0)
6172 {
6173 pack_fclose(f);
6174 return false;
6175 }
6176
6177 //write the triforce pieces info and make sure it worked
6178 //really do this?
6179
6180 //write the game icons info and make sure it worked
6181 if(writegameicons(f, &header)!=0)
6182 {
6183 pack_fclose(f);
6184 return false;
6185 }
6186
6187 //write the misc colors info and map styles info and make sure it worked
6188 if(writemisccolors(f, &header)!=0)
6189 {
6190 pack_fclose(f);
6191 return false;
6192 }
6193
6194 //write the door combo sets and make sure it worked
6195 if(writedoorcombosets(f, &header)!=0)
6196 {
6197 pack_fclose(f);
6198 return false;
6199 }
6200
6201 //write the template screens and make sure it worked
6202 //really do this?
6203
6204 pack_fclose(f);
6205 return true;
6206 }
6207
6208 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6209 {
6210 //open the file
6211 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6212
6213 if(!f)
6214 return false;
6215
6216 dword section_id=ID_SUBSCREEN;
6217 dword s_version=V_SUBSCREEN;
6218
6219 if(!p_mputl(section_id,f))
6220 {
6221 pack_fclose(f);
6222 return false;
6223 }
6224
6225 if(!p_iputw(s_version,f))
6226 {
6227 pack_fclose(f);
6228 return false;
6229 }
6230
6231 if(!write_deprecated_section_cversion(s_version,f))
6232 {
6233 pack_fclose(f);
6234 return false;
6235 }
6236
6237 if(savefrom.write(f))
6238 {
6239 pack_fclose(f);
6240 return false;
6241 }
6242
6243 pack_fclose(f);
6244 return true;
6245 }
6246
6247 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6248 {
6249 //open the file
6250 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6251
6252 if(!f)
6253 return false;
6254
6255 dword section_id;
6256 dword s_version;
6257
6258 if(!p_mgetl(&section_id,f))
6259 {
6260 pack_fclose(f);
6261 return false;
6262 }
6263
6264 if(section_id!=ID_SUBSCREEN)
6265 {
6266 pack_fclose(f);
6267 return false;
6268 }
6269
6270 if(!p_igetw(&s_version,f))
6271 {
6272 pack_fclose(f);
6273 return false;
6274 }
6275
6276 if(!read_deprecated_section_cversion(f))
6277 {
6278 pack_fclose(f);
6279 return false;
6280 }
6281
6282 if(s_version < 8)
6283 {
6284 subscreen_group g;
6285 memset(&g,0,sizeof(subscreen_group));
6286 if(read_one_old_subscreen(f,&g,s_version)!=0)
6287 {
6288 pack_fclose(f);
6289 return false;
6290 }
6291 if(g.ss_type != loadto.sub_type)
6292 {
6293 pack_fclose(f);
6294 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6295 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6296 return false;
6297 }
6298 loadto.clear();
6299 if(g.objects[0].type != ssoNULL)
6300 loadto.load_old(g);
6301 }
6302 else
6303 {
6304 ZCSubscreen tmp = ZCSubscreen();
6305 if (tmp.read(f, s_version))
6306 {
6307 pack_fclose(f);
6308 return false;
6309 }
6310 if(tmp.sub_type != loadto.sub_type)
6311 {
6312 pack_fclose(f);
6313 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6314 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6315 return false;
6316 }
6317 loadto.clear();
6318 loadto = tmp;
6319 }
6320
6321 pack_fclose(f);
6322 return true;
6323 }
6324
6325 bool setMapCount2(int32_t c)
6326 {
6327 int32_t oldmapcount=map_count;
6328 int32_t cur_map=Map.getCurrMap();
6329
6330 bound(c,1,MAXMAPS);
6331 map_count=c;
6332
6333 try
6334 {
6335 TheMaps.resize(c*MAPSCRS);
6336 Map.force_refr_pointer();
6337 map_autolayers.resize(c*6);
6338 }
6339 catch(...)
6340 {
6341 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6342 return false;
6343 }
6344
6345 bound(cur_map,0,c-1);
6346 if(map_count>oldmapcount)
6347 {
6348 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6349 {
6350 Map.setCurrMap(mc);
6351
6352 for(int32_t ms=0; ms<MAPSCRS; ms++)
6353 {
6354 Map.clearscr(ms);
6355 }
6356 }
6357 Map.setCurrMap(cur_map);
6358 }
6359 else
6360 {
6361 Map.setCurrMap(cur_map);
6362 if(!layers_valid(Map.CurrScr()))
6363 fix_layers(Map.CurrScr(), false);
6364
6365 for(int32_t i=0; i<MAXDMAPS; i++)
6366 {
6367 if(DMaps[i].map>=map_count)
6368 {
6369 DMaps[i].map=map_count-1;
6370 }
6371 }
6372 }
6373
6374 return true;
6375 }
6376
6377 extern BITMAP *bmap;
6378
6379 static bool loading_file_new = false;
6380 int32_t init_quest(std::string tileset_path)
6381 {
6382 if (tileset_path.empty())
6383 tileset_path = DEFAULT_TILESET;
6384
6385 loading_file_new = true;
6386 load_quest(tileset_path.c_str());
6387 loading_file_new = false;
6388
6389 set_window_title("ZC Editor - Untitled Quest");
6390 zinit.last_map = 0;
6391 zinit.last_screen = 0;
6392
6393 if(bmap != NULL)
6394 {
6395 destroy_bitmap(bmap);
6396 bmap=NULL;
6397 }
6398
6399 return 0;
6400 }
6401
6402 void set_questpwd(std::string_view pwd, bool use_keyfile)
6403 {
6404 header.use_keyfile=use_keyfile;
6405
6406 // string_view actually has some quirks that make it less than ideal here.
6407 // It'd probably be best to replace it, but this works for now.
6408 memset(header.password, 0, 256);
6409 strcpy(header.password, pwd.data());
6410 header.dirty_password=true;
6411
6412 cvs_MD5Context ctx;
6413 cvs_MD5Init(&ctx);
6414 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6415 cvs_MD5Final(header.pwd_hash, &ctx);
6416 }
6417
6418
6419 bool is_null_pwd_hash(uint8_t *pwd_hash)
6420 {
6421 cvs_MD5Context ctx;
6422 uint8_t md5sum[16];
6423 char pwd[2]="";
6424
6425 cvs_MD5Init(&ctx);
6426 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6427 cvs_MD5Final(md5sum, &ctx);
6428
6429 return (memcmp(md5sum,pwd_hash,16)==0);
6430 }
6431
6432 static DIALOG pwd_dlg[] =
6433 {
6434 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6435 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6436 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6437 // 2 (filename)
6438 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6439 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6440 // 4 (challenge hash)
6441 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6442 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6443 // 6 (password)
6444 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6445 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6446 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6447 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6448 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6449 };
6450
6451 int32_t reverse_string(char* str)
6452 {
6453
6454 if(NULL==str)
6455 {
6456 return -1; //no string
6457 }
6458
6459 int32_t l=(int32_t)strlen(str)-1; //get the string length
6460
6461 if(1==l)
6462 {
6463 return 1;
6464 }
6465
6466 char c;
6467
6468 for(int32_t x=0; x < l; x++,l--)
6469 {
6470 c = str[x];
6471 str[x] = str[l];
6472 str[l] = c;
6473 }
6474
6475 return 0;
6476 }
6477
6478 #ifdef __GNUC__
6479 #pragma GCC diagnostic push
6480 #pragma GCC diagnostic ignored "-Wunreachable-code"
6481 #endif
6482
6483 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6484 {
6485
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6486 11 return 1;
6487
6488 #ifdef __EMSCRIPTEN__
6489 return 1;
6490 #endif
6491
6492 //Protection against compiling a release version with password protection off.
6493 static bool passguard = false;
6494
6495 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6496 #define MUST_HAVE_PASSWORD
6497 passguard = true;
6498 #endif
6499
6500 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6501 #if (defined _MSC_VER || defined _NPASS)
6502 return 1;
6503 #endif
6504 #endif
6505 if(devpwd()) return 1;
6506
6507 char hash_string[33];
6508
6509 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6510 {
6511 return 1;
6512 }
6513
6514 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6515 return true;
6516
6517 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6518 pwd_dlg[2].dp=get_filename(filename);
6519 cvs_MD5Context ctx;
6520 uint8_t md5sum[16]={0};
6521 char response[33]="";
6522 char prompt[256]="";
6523
6524 memcpy(md5sum, hdr->pwd_hash, 16);
6525
6526 for(int32_t i=0; i<300; ++i)
6527 {
6528 for(int32_t j=0; j<16; ++j)
6529 {
6530 sprintf(response+j*2, "%02x", md5sum[j]);
6531 }
6532
6533 if(i&1)
6534 {
6535 reverse_string(response);
6536 }
6537
6538 if(i==149)
6539 {
6540 strcpy(hash_string, response);
6541 }
6542
6543 cvs_MD5Init(&ctx);
6544 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6545 cvs_MD5Final(md5sum, &ctx);
6546 }
6547
6548 pwd_dlg[4].dp=hash_string;
6549
6550 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6551 {
6552 sprintf(prompt,"%s",response);
6553 }
6554
6555 pwd_dlg[6].dp=prompt;
6556
6557 large_dialog(pwd_dlg);
6558
6559 int32_t cancel = do_zqdialog(pwd_dlg,6);
6560
6561 if(cancel == 8)
6562 return 2;
6563
6564 bool ret=check_questpwd(hdr, prompt);
6565
6566 if(!ret)
6567 {
6568 ret=(strcmp(response,prompt)==0);
6569 }
6570 return ret ? 1 : 0;
6571 11 }
6572
6573 void set_rules(byte* newrules);
6574 11 void popup_bugfix_dlg(const char* cfg)
6575 {
6576 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6577
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6578 {
6579
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6580
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6581 "\nWould you like to apply them?"
6582 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6583 11 [&](bool ret,bool dsa)
6584 {
6585 if(ret)
6586 {
6587 applyRuleTemplate(ruletemplateFixCompat);
6588 }
6589 if(dsa)
6590 {
6591 zc_set_config("zquest",cfg,1);
6592 }
6593 },
6594
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6595 0,false, //timeout - none
6596 true //"Don't show this again"
6597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6598 11 }
6599 11 }
6600
6601 #ifdef __GNUC__
6602 #pragma GCC diagnostic pop
6603 #endif
6604
6605 11 int32_t load_quest(const char *filename, bool show_progress)
6606 {
6607 char buf[2048];
6608 byte skip_flags[4];
6609
6610 11 dword tileset_flags = 0;
6611
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6612 {
6613 44 skip_flags[i]=0;
6614 44 }
6615
2/2
✓ Branch 0 taken 7623 times.
✓ Branch 1 taken 11 times.
7634 for(int32_t i=0; i<qr_MAX; i++)
6616 7623 set_qr(i,0);
6617 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6618
6619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6620 {
6621 init_quest(DEFAULT_TILESET);
6622 }
6623 else
6624 {
6625 11 int32_t accessret = quest_access(filename, &header);
6626
6627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6628 {
6629 init_quest(DEFAULT_TILESET);
6630
6631 if(accessret == 0)
6632 ret=qe_pwd;
6633 else
6634 ret=qe_cancel;
6635 }
6636 else
6637 {
6638 11 Map.clear();
6639 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6640 11 Map.setCurrScr(zinit.last_screen);
6641
6642
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
6643
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6644
6645 extern int32_t current_mappage;
6646 11 current_mappage = 0;
6647 11 bool found_default = false;
6648
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6649 {
6650 83 auto &pg = map_page[q];
6651
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6652 {
6653 2 current_mappage = q;
6654 2 break;
6655 }
6656
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6657 72 continue;
6658 else
6659 {
6660 9 current_mappage = q;
6661 9 found_default = true;
6662 }
6663 9 }
6664
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6665
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6666
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6667 11 saved = true;
6668
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6669
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule");
6670
6671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6672 {
6673 destroy_bitmap(bmap);
6674 bmap=NULL;
6675 }
6676
6677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6678 {
6679 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6680 set_window_title(buf);
6681 }
6682 11 }
6683 }
6684
6685 11 Map.ClearCommandHistory();
6686
6687
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6688 {
6689 void load_size_poses();
6690 load_size_poses();
6691 }
6692
6693 11 return ret;
6694 }
6695
6696 int32_t load_tileset(const char *filename, dword tsetflags)
6697 {
6698 byte skip_flags[4];
6699
6700 for(int32_t i=0; i<4; ++i)
6701 skip_flags[i]=0;
6702 for(int32_t i=0; i<qr_MAX; i++)
6703 set_qr(i,0);
6704 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6705
6706 if(ret!=qe_OK)
6707 init_quest(DEFAULT_TILESET);
6708 else
6709 {
6710 if(tsetflags & TILESET_BUGFIX)
6711 applyRuleTemplate(ruletemplateFixCompat);
6712
6713 int32_t accessret = quest_access(filename, &header);
6714
6715 if(accessret != 1)
6716 {
6717 init_quest(DEFAULT_TILESET);
6718
6719 if(accessret == 0)
6720 ret=qe_pwd;
6721 else
6722 ret=qe_cancel;
6723 }
6724 else
6725 {
6726 Map.clear();
6727 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6728 Map.setCurrScr(zinit.last_screen);
6729 extern int32_t current_mappage;
6730 current_mappage = 0;
6731 bool found_default = false;
6732 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6733 {
6734 auto &pg = map_page[q];
6735 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6736 {
6737 current_mappage = q;
6738 break;
6739 }
6740 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6741 continue;
6742 else
6743 {
6744 current_mappage = q;
6745 found_default = true;
6746 }
6747 }
6748 refresh(rALL);
6749 refresh_pal();
6750 set_rules(quest_rules);
6751
6752 if(bmap != NULL)
6753 {
6754 destroy_bitmap(bmap);
6755 bmap=NULL;
6756 }
6757
6758 set_window_title("ZC Editor - Untitled Quest");
6759 first_save = saved = false;
6760 memset(filepath,0,255);
6761 memset(temppath,0,255);
6762 }
6763 }
6764
6765 Map.ClearCommandHistory();
6766
6767 return ret;
6768 }
6769
6770 130 bool write_midi(MIDI *m,PACKFILE *f)
6771 {
6772 int32_t c;
6773
6774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6775
6776
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6777 {
6778
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6779
6780
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6781 {
6782
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6783 return false;
6784 1264 }
6785 4160 }
6786
6787 130 return true;
6788 130 }
6789
6790 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6791 {
6792 9 dword section_id=ID_HEADER;
6793 9 dword section_version=V_HEADER;
6794 9 dword section_size=0;
6795
6796 //file header string
6797
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6798 {
6799 new_return(1);
6800 }
6801
6802 //section id
6803
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6804 {
6805 new_return(2);
6806 }
6807
6808 //section version info
6809
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6810 {
6811 new_return(3);
6812 }
6813
6814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6815 {
6816 new_return(4);
6817 }
6818
6819
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6820 {
6821 18 fake_pack_writing=(writecycle==0);
6822
6823 //section size
6824
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6825 {
6826 new_return(5);
6827 }
6828
6829 18 writesize=0;
6830
6831 //finally... section data
6832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6833 {
6834 new_return(6);
6835 }
6836
6837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6838 {
6839 new_return(7);
6840 }
6841
6842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6843 {
6844 new_return(8);
6845 }
6846
6847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6848 {
6849 new_return(10);
6850 }
6851
6852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6853 {
6854 new_return(11);
6855 }
6856
6857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6858 {
6859 new_return(12);
6860 }
6861
6862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6863 {
6864 new_return(13);
6865 }
6866
6867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6868 {
6869 new_return(14);
6870 }
6871
6872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6873 {
6874 new_return(15);
6875 }
6876
6877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6878 {
6879 new_return(16);
6880 }
6881
6882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6883 {
6884 new_return(17);
6885 }
6886
6887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6888 {
6889 new_return(19);
6890 }
6891
6892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6893 //this is for map count, it seems. -Z
6894 {
6895 new_return(20);
6896 }
6897
6898 18 auto version = getVersion();
6899
6900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6901 {
6902 new_return(21);
6903 }
6904
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6905 {
6906 new_return(22);
6907 }
6908
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6909 {
6910 new_return(23);
6911 }
6912 // Fourth component is deprecated.
6913
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6914 {
6915 new_return(24);
6916 }
6917
6918 // Numerous prerelease stages is deprecated.
6919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6920 {
6921 new_return(25);
6922 }
6923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6924 {
6925 new_return(26);
6926 }
6927
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6928 {
6929 new_return(27);
6930 }
6931
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6932 {
6933 new_return(28);
6934 }
6935
6936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6937 {
6938 new_return(29);
6939 }
6940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6941 {
6942 new_return(30);
6943 }
6944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6945 {
6946 new_return(31);
6947 }
6948
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6949 {
6950 new_return(32);
6951 }
6952
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6953 {
6954 new_return(33);
6955 }
6956
6957 // This is no longer set to anything.
6958 const char* tempsig[256];
6959 18 memset(tempsig, 0, 256);
6960
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6961 {
6962 new_return(34);
6963 }
6964
6965 char tempcompilersig[256];
6966 18 memset(tempcompilersig, 0, 256);
6967 18 strcpy(tempcompilersig, COMPILER_NAME);
6968
6969
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6970 {
6971 new_return(35);
6972 }
6973
6974 char tempcompilerversion[256];
6975 18 memset(tempcompilerversion, 0, 256);
6976 #ifdef _MSC_VER
6977 zc_itoa(_MSC_VER,tempcompilerversion,10);
6978 #else
6979 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6980 #endif
6981
6982
6983
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6984 {
6985 new_return(36);
6986 }
6987
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6989 {
6990 new_return(37);
6991 }
6992
6993 // V_ZC_COMPILERSIG - a deprecated version field.
6994
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6995 {
6996 new_return(38);
6997 }
6998 #ifdef _MSC_VER
6999 if(!p_iputl((_MSC_VER / 100),f))
7000 {
7001 new_return(39);
7002 }
7003 #else
7004
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7005 {
7006 new_return(39);
7007 }
7008 #endif
7009
7010
7011
7012 #ifdef _MSC_VER
7013 if(!p_iputl((_MSC_VER % 100),f))
7014 {
7015 new_return(41);
7016 }
7017 #else
7018
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7019 {
7020 new_return(41);
7021 }
7022 #endif
7023
7024 #ifdef _MSC_VER
7025 # if _MSC_VER >= 1400
7026 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7027 {
7028 new_return(40);
7029 }
7030 # else
7031 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7032 {
7033 new_return(40);
7034 }
7035 #endif
7036 #else
7037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7038 {
7039 new_return(40);
7040 }
7041 #endif
7042
7043 #ifdef _MSC_VER
7044 if(!p_iputl((_MSC_BUILD),f))
7045 {
7046 new_return(42);
7047 }
7048 #else
7049
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7050 {
7051 new_return(42);
7052 }
7053 #endif
7054
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7055 {
7056 new_return(43);
7057 }
7058
7059 // Modules were removed (replaced by zinfo).
7060 char tempmodulename[1024];
7061 18 memset(tempmodulename, 0, 1024);
7062
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7063 {
7064 new_return(44);
7065 }
7066
7067 char tempdate[256];
7068 18 memset(tempdate, 0, 256);
7069 18 strcpy(tempdate, __DATE__);
7070
7071
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7072 {
7073 new_return(45);
7074 }
7075 char temptime[256];
7076 18 memset(temptime, 0, 256);
7077 18 strcpy(temptime, __TIME__);
7078
7079
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7080 {
7081 new_return(46);
7082 }
7083
7084
7085 char temptimezone[6];
7086 18 memset(temptimezone, 0, 6);
7087 18 strcpy(temptimezone, __TIMEZONE__);
7088
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7089 {
7090 new_return(47);
7091 }
7092
7093
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7094 {
7095 new_return(48);
7096 }
7097
7098
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7099 {
7100 new_return(49);
7101 }
7102
7103
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7104 {
7105 new_return(50);
7106 }
7107
7108
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7109 {
7110 9 section_size=writesize;
7111 9 }
7112 18 }
7113
7114
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7115 {
7116 char ebuf[80];
7117 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7118 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7119 }
7120
7121 9 new_return(0);
7122 }
7123
7124 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7125 {
7126 //these are here to bypass compiler warnings about unused arguments
7127 9 Header=Header;
7128
7129 9 dword section_id=ID_RULES;
7130 9 dword section_version=V_RULES;
7131 9 dword section_size=0;
7132
7133 //section id
7134
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7135 {
7136 new_return(1);
7137 }
7138
7139 //section version info
7140
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7141 {
7142 new_return(2);
7143 }
7144
7145
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7146 {
7147 new_return(3);
7148 }
7149
7150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7151 {
7152 new_return(6);
7153 }
7154
7155
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7156 {
7157 18 fake_pack_writing=(writecycle==0);
7158
7159 //section size
7160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7161 {
7162 new_return(4);
7163 }
7164
7165 18 writesize=0;
7166
7167 //finally... section data
7168
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7169 {
7170 new_return(5);
7171 }
7172
7173
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7174 {
7175 9 section_size=writesize;
7176 9 }
7177 18 }
7178
7179
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7180 {
7181 char ebuf[80];
7182 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7183 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7184 }
7185
7186 9 new_return(0);
7187 }
7188
7189
7190 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7191 {
7192 //these are here to bypass compiler warnings about unused arguments
7193 9 Header=Header;
7194
7195 9 dword section_id=ID_DOORS;
7196 9 dword section_version=V_DOORS;
7197 9 dword section_size=0;
7198
7199 //section id
7200
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7201 {
7202 new_return(1);
7203 }
7204
7205 //section version info
7206
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7207 {
7208 new_return(2);
7209 }
7210
7211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7212 {
7213 new_return(3);
7214 }
7215
7216
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7217 {
7218 18 fake_pack_writing=(writecycle==0);
7219
7220 //section size
7221
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7222 {
7223 new_return(4);
7224 }
7225
7226 18 writesize=0;
7227
7228 //finally... section data
7229
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7230 {
7231 new_return(5);
7232 }
7233
7234
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7235 {
7236 //name
7237 char name[21];
7238 320 memset(name, 21, (char)0);
7239 320 strcpy(name, DoorComboSetNames[i].c_str());
7240
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7241 {
7242 new_return(6);
7243 }
7244
7245 //up door
7246
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7247 {
7248
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7249 {
7250
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7251 {
7252 new_return(7);
7253 }
7254 11520 }
7255 2880 }
7256
7257
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7258 {
7259
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7260 {
7261
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7262 {
7263 new_return(8);
7264 }
7265 11520 }
7266 2880 }
7267
7268 //down door
7269
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7270 {
7271
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7272 {
7273
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7274 {
7275 new_return(9);
7276 }
7277 11520 }
7278 2880 }
7279
7280
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7281 {
7282
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7283 {
7284
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7285 {
7286 new_return(10);
7287 }
7288 11520 }
7289 2880 }
7290
7291
7292 //left door
7293
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7294 {
7295
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7296 {
7297
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7298
7299 {
7300 new_return(11);
7301 }
7302 17280 }
7303 2880 }
7304
7305
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7306 {
7307
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7308 {
7309
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7310 {
7311 new_return(12);
7312 }
7313 17280 }
7314 2880 }
7315
7316 //right door
7317
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7318 {
7319
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7320 {
7321
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7322 {
7323 new_return(13);
7324 }
7325 17280 }
7326 2880 }
7327
7328
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7329 {
7330
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7331 {
7332
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7333 {
7334 new_return(14);
7335 }
7336 17280 }
7337 2880 }
7338
7339
7340 //up bomb rubble
7341
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7342 {
7343
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7344 {
7345 new_return(15);
7346 }
7347 640 }
7348
7349
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7350 {
7351
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7352 {
7353 new_return(16);
7354 }
7355 640 }
7356
7357 //down bomb rubble
7358
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7359 {
7360
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7361 {
7362 new_return(17);
7363 }
7364 640 }
7365
7366
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7367 {
7368
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7369 {
7370 new_return(18);
7371 }
7372 640 }
7373
7374 //left bomb rubble
7375
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7376 {
7377
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7378 {
7379 new_return(19);
7380 }
7381 960 }
7382
7383
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7384 {
7385
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7386 {
7387 new_return(20);
7388 }
7389 960 }
7390
7391 //right bomb rubble
7392
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7393 {
7394
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7395 {
7396 new_return(21);
7397 }
7398 960 }
7399
7400
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7401 {
7402
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7403 {
7404 new_return(22);
7405 }
7406 960 }
7407
7408 //walkthrough stuff
7409
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7410 {
7411
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7412 {
7413 new_return(23);
7414 }
7415 1280 }
7416
7417
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7418 {
7419
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7420 {
7421 new_return(24);
7422 }
7423 1280 }
7424
7425 //flags
7426
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7427 {
7428
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7429 {
7430 new_return(25);
7431 }
7432 640 }
7433 320 }
7434
7435
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7436 {
7437 9 section_size=writesize;
7438 9 }
7439 18 }
7440
7441
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7442 {
7443 char ebuf[80];
7444 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7445 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7446 }
7447
7448 9 new_return(0);
7449 }
7450
7451 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7452 {
7453 //these are here to bypass compiler warnings about unused arguments
7454 9 version=version;
7455 9 build=build;
7456
7457 9 word dmap_count=count_dmaps();
7458 9 dword section_id=ID_DMAPS;
7459 9 dword section_version=V_DMAPS;
7460 9 dword section_size=0;
7461
7462 //section id
7463
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7464 {
7465 new_return(1);
7466 }
7467
7468 //section version info
7469
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7470 {
7471 new_return(2);
7472 }
7473
7474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7475 {
7476 new_return(3);
7477 }
7478
7479
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7480 {
7481 18 fake_pack_writing=(writecycle==0);
7482
7483 //section size
7484
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7485 {
7486 new_return(4);
7487 }
7488
7489 18 writesize=0;
7490
7491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7493
7494 //finally... section data
7495
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7496 {
7497 new_return(5);
7498 }
7499
7500
7501
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7502 {
7503 9216 DMaps[i].validate_subscreens();
7504
7505
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7506 {
7507 new_return(6);
7508 }
7509
7510
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7511 {
7512 new_return(7);
7513 }
7514
7515
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7516 {
7517 new_return(8);
7518 }
7519
7520
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7521 {
7522 new_return(9);
7523 }
7524
7525
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7526 {
7527 new_return(10);
7528 }
7529
7530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7531 {
7532 new_return(11);
7533 }
7534
7535
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7536 {
7537 new_return(12);
7538 }
7539
7540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7541 {
7542 new_return(13);
7543 }
7544
7545
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7546 {
7547
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7548 {
7549 new_return(14);
7550 }
7551 73728 }
7552
7553
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7554 {
7555 new_return(15);
7556 }
7557
7558
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7559 {
7560 new_return(16);
7561 }
7562
7563
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7564 {
7565 new_return(17);
7566 }
7567
7568
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7569 {
7570 new_return(18);
7571 }
7572
7573
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_1_cset,f))
7574 {
7575 new_return(19);
7576 }
7577
7578
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7579 {
7580 new_return(20);
7581 }
7582
7583
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_2_cset,f))
7584 {
7585 new_return(21);
7586 }
7587
7588
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7589 {
7590 new_return(22);
7591 }
7592
7593
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_1_cset,f))
7594 {
7595 new_return(23);
7596 }
7597
7598
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7599 {
7600 new_return(24);
7601 }
7602
7603
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_2_cset,f))
7604 {
7605 new_return(25);
7606 }
7607
7608
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7609 {
7610 new_return(26);
7611 }
7612
7613
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7614 {
7615 new_return(25);
7616 }
7617
7618
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7619 {
7620 new_return(26);
7621 }
7622
7623
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7624 {
7625 new_return(27);
7626 }
7627
7628 byte disabled[32];
7629 9216 memset(disabled,0,32);
7630
7631
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7632 {
7633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7634 {
7635 disabled[j/8] |= (1 << (j%8));
7636 }
7637 2359296 }
7638
7639
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7640 {
7641 new_return(28);
7642 }
7643
7644
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7645 {
7646 new_return(29);
7647 }
7648
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7649 {
7650 new_return(30);
7651 }
7652
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7653 {
7654 new_return(31);
7655 }
7656
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7657 {
7658
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7659 {
7660 new_return(32);
7661 }
7662
7663 73728 }
7664
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7665 {
7666
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7667 {
7668
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7669 {
7670 new_return(33);
7671 }
7672 4792320 }
7673 73728 }
7674
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7675 {
7676 new_return(34);
7677 }
7678
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7679 {
7680 new_return(35);
7681 }
7682
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7683 {
7684
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7685 {
7686 new_return(36);
7687 }
7688 73728 }
7689
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7690 {
7691
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7692 {
7693
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7694 {
7695 new_return(37);
7696 }
7697 4792320 }
7698 73728 }
7699
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7700 {
7701 new_return(38);
7702 }
7703
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7704 {
7705
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7706 {
7707 new_return(39);
7708 }
7709 73728 }
7710
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7711 {
7712
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7713 {
7714
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7715 {
7716 new_return(40);
7717 }
7718 4792320 }
7719 73728 }
7720
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7721 {
7722 new_return(41);
7723 }
7724
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7725 {
7726 new_return(42);
7727 }
7728
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7729 {
7730 new_return(43);
7731 }
7732
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7733 {
7734 new_return(44);
7735 }
7736
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7737 {
7738 new_return(45);
7739 }
7740
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7741 new_return(46);
7742
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7743 new_return(47);
7744 9216 }
7745
7746
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7747 {
7748 9 section_size=writesize;
7749 9 }
7750 18 }
7751
7752
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7753 {
7754 char ebuf[80];
7755 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7756 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7757 }
7758
7759 9 new_return(0);
7760 }
7761
7762 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7763 {
7764 //these are here to bypass compiler warnings about unused arguments
7765 9 Header=Header;
7766
7767 9 dword section_id=ID_COLORS;
7768 9 dword section_version=V_COLORS;
7769 9 dword section_size = 0;
7770
7771 //section id
7772
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7773 {
7774 new_return(1);
7775 }
7776
7777
7778 //section version info
7779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7780 {
7781 new_return(2);
7782 }
7783
7784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7785 {
7786 new_return(3);
7787 }
7788
7789
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7790 {
7791 18 fake_pack_writing=(writecycle==0);
7792
7793 //section size
7794
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7795 {
7796 new_return(4);
7797 }
7798
7799 18 writesize=0;
7800
7801
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7802 {
7803 new_return(5);
7804 }
7805
7806
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7807 {
7808 new_return(6);
7809 }
7810
7811
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7812 {
7813 new_return(7);
7814 }
7815
7816
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7817 {
7818 new_return(8);
7819 }
7820
7821
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7822 {
7823 new_return(9);
7824 }
7825
7826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7827 {
7828 new_return(10);
7829 }
7830
7831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7832 {
7833 new_return(11);
7834 }
7835
7836
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7837 {
7838 new_return(12);
7839 }
7840
7841
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7842 {
7843 new_return(13);
7844 }
7845
7846
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7847 {
7848 new_return(14);
7849 }
7850
7851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7852 {
7853 new_return(15);
7854 }
7855
7856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7857 {
7858 new_return(16);
7859 }
7860
7861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7862 {
7863 new_return(17);
7864 }
7865
7866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7867 {
7868 new_return(18);
7869 }
7870
7871
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7872 {
7873 new_return(19);
7874 }
7875
7876
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7877 {
7878 new_return(20);
7879 }
7880
7881
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7882 {
7883 new_return(21);
7884 }
7885
7886
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7887 {
7888 new_return(22);
7889 }
7890
7891
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7892 {
7893 new_return(23);
7894 }
7895
7896
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7897 {
7898 new_return(24);
7899 }
7900
7901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7902 {
7903 new_return(31);
7904 }
7905
7906
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7907 {
7908 new_return(32);
7909 }
7910
7911
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7912 {
7913 new_return(33);
7914 }
7915
7916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7917 {
7918 new_return(34);
7919 }
7920
7921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7922 {
7923 new_return(35);
7924 }
7925
7926
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7927 {
7928 new_return(36);
7929 }
7930
7931
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7932 {
7933 new_return(37);
7934 }
7935
7936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7937 {
7938 new_return(38);
7939 }
7940
7941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7942 {
7943 new_return(39);
7944 }
7945
7946
7947
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7948 {
7949 9 section_size=writesize;
7950 9 }
7951 18 }
7952
7953
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7954 {
7955 char ebuf[80];
7956 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7957 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7958 }
7959
7960 9 new_return(0);
7961 }
7962
7963 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7964 {
7965 //these are here to bypass compiler warnings about unused arguments
7966 9 Header=Header;
7967
7968 9 dword section_id=ID_ICONS;
7969 9 dword section_version=V_ICONS;
7970 9 dword section_size = 0;
7971
7972 //section id
7973
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7974 {
7975 new_return(1);
7976 }
7977
7978 //section version info
7979
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7980 {
7981 new_return(2);
7982 }
7983
7984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7985 {
7986 new_return(3);
7987 }
7988
7989
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7990 {
7991 18 fake_pack_writing=(writecycle==0);
7992
7993 //section size
7994
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7995 {
7996 new_return(4);
7997 }
7998
7999 18 writesize=0;
8000
8001
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8002 {
8003
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8004 {
8005 new_return(5);
8006 }
8007 72 }
8008
8009
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8010 {
8011 9 section_size=writesize;
8012 9 }
8013 18 }
8014
8015
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8016 {
8017 char ebuf[80];
8018 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8019 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8020 }
8021
8022 9 new_return(0);
8023 }
8024
8025 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8026 {
8027 //these are here to bypass compiler warnings about unused arguments
8028 9 Header=Header;
8029
8030 9 dword section_id=ID_MISC;
8031 9 dword section_version=V_MISC;
8032 9 word shops=count_shops(&QMisc);
8033 9 word infos=count_infos(&QMisc);
8034 9 word warprings=count_warprings(&QMisc);
8035 9 word triforces=8;
8036 9 dword section_size = 0;
8037
8038 //section id
8039
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8040 {
8041 new_return(1);
8042 }
8043
8044
8045 //section version info
8046
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8047 {
8048 new_return(2);
8049 }
8050
8051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8052 {
8053 new_return(3);
8054 }
8055
8056
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8057 {
8058 18 fake_pack_writing=(writecycle==0);
8059
8060 //section size
8061
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8062 {
8063 new_return(4);
8064 }
8065
8066 18 writesize=0;
8067
8068 //shops
8069
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8070 {
8071 new_return(5);
8072 }
8073
8074
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8075 {
8076
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8077 {
8078 new_return(6);
8079 }
8080
8081
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8082 {
8083
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8084 {
8085 new_return(7);
8086 }
8087 480 }
8088
8089
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8090 {
8091
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8092 {
8093 new_return(8);
8094 }
8095 480 }
8096
8097
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8098 {
8099
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8100 {
8101 new_return(9);
8102 }
8103 480 }
8104 160 }
8105
8106 //infos
8107
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8108 {
8109 new_return(10);
8110 }
8111
8112
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8113 {
8114
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8115 {
8116 new_return(11);
8117 }
8118
8119
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8120 {
8121
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8122 {
8123 new_return(12);
8124 }
8125 480 }
8126
8127
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8128 {
8129
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8130 {
8131 new_return(13);
8132 }
8133 480 }
8134 160 }
8135
8136 //warp rings
8137
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8138 {
8139 new_return(14);
8140 }
8141
8142
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8143 {
8144
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8145 {
8146
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8147 {
8148 new_return(15);
8149 }
8150 1872 }
8151
8152
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8153 {
8154
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8155 {
8156 new_return(16);
8157 }
8158 1872 }
8159
8160
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8161 {
8162 new_return(17);
8163 }
8164 208 }
8165
8166 //triforce pieces
8167
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8168 {
8169
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8170 {
8171 new_return(18);
8172 }
8173 144 }
8174
8175 //end string
8176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8177 {
8178 new_return(19);
8179 }
8180
8181 //V_MISC >= 8
8182
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8183 {
8184
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8185 {
8186
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8187 {
8188 new_return(20);
8189 }
8190 480 }
8191 160 }
8192 //V_MISC >= 9
8193
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8194 {
8195
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8196 new_return(21);
8197 576 }
8198
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8199 {
8200
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8201
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8202 new_return(22);
8203 576 }
8204 //V_MISC >= 11
8205
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8206 new_return(23);
8207
8208 //V_MISC >= 12
8209
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8210 {
8211
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8212 new_return(24);
8213 4608 }
8214
8215 //V_MISC >= 13
8216
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8217 {
8218 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8219
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8220 new_return(25);
8221
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8222 {
8223
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8224 new_return(25);
8225
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8226 new_return(25);
8227 3456 }
8228
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8229 new_return(25);
8230
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8231 new_return(25);
8232 1152 }
8233
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8234 {
8235 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8236
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8237 new_return(26);
8238
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8239 {
8240
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8241 new_return(26);
8242
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8243 new_return(26);
8244
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8245 new_return(26);
8246
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8247 new_return(26);
8248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8249 new_return(26);
8250 13824 }
8251 4608 }
8252
8253 //V_MISC >= 14
8254
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8255 {
8256
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8257 new_return(27);
8258 4608 }
8259
8260
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8261 {
8262 9 section_size=writesize;
8263 9 }
8264 18 }
8265
8266
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8267 {
8268 char ebuf[80];
8269 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8270 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8271 }
8272
8273 9 new_return(0);
8274 }
8275
8276 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8277 {
8278 //these are here to bypass compiler warnings about unused arguments
8279 9 Header=Header;
8280
8281 9 dword section_id=ID_ITEMS;
8282 9 dword section_version=V_ITEMS;
8283 // dword section_size=0;
8284 9 dword section_size = 0;
8285
8286 //section id
8287
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8288 {
8289 new_return(1);
8290 }
8291
8292 //section version info
8293
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8294 {
8295 new_return(2);
8296 }
8297
8298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8299 {
8300 new_return(3);
8301 }
8302
8303
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8304 {
8305 18 fake_pack_writing=(writecycle==0);
8306
8307 //section size
8308
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8309 {
8310 new_return(4);
8311 }
8312
8313 18 writesize=0;
8314
8315 //finally... section data
8316
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8317 {
8318 new_return(5);
8319 }
8320
8321
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8322 {
8323
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8324 {
8325 new_return(5);
8326 }
8327 4608 }
8328
8329
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8330 {
8331
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8332 {
8333 new_return(6);
8334 }
8335
8336
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8337 {
8338 new_return(7);
8339 }
8340
8341
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8342 {
8343 new_return(8);
8344 }
8345
8346
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8347 {
8348 new_return(9);
8349 }
8350
8351
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8352 {
8353 new_return(10);
8354 }
8355
8356
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8357 {
8358 new_return(11);
8359 }
8360
8361
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8362 {
8363 new_return(12);
8364 }
8365
8366
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].family,f))
8367 {
8368 new_return(13);
8369 }
8370
8371
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].fam_type,f))
8372 {
8373 new_return(14);
8374 }
8375
8376
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8377 {
8378 new_return(14);
8379 }
8380
8381
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8382 {
8383 new_return(15);
8384 }
8385
8386
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8387 {
8388 new_return(16);
8389 }
8390
8391
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8392 {
8393 new_return(17);
8394 }
8395
8396
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8397 {
8398 new_return(18);
8399 }
8400
8401
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8402 {
8403 new_return(19);
8404 }
8405
8406
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8407 {
8408 new_return(21);
8409 }
8410
8411
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8412 {
8413 new_return(22);
8414 }
8415
8416
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8417 {
8418 new_return(23);
8419 }
8420
8421
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8422 {
8423
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8424 {
8425 new_return(24);
8426 }
8427 36864 }
8428
8429
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8430 {
8431
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8432 {
8433 new_return(25);
8434 }
8435 9216 }
8436
8437
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8438 {
8439 new_return(26);
8440 }
8441
8442
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8443 {
8444 new_return(27);
8445 }
8446
8447
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8448 {
8449 new_return(28);
8450 }
8451
8452
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8453 {
8454 new_return(29);
8455 }
8456
8457
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8458 {
8459 new_return(30);
8460 }
8461
8462
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8463 {
8464 new_return(31);
8465 }
8466
8467
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8468 {
8469 new_return(32);
8470 }
8471
8472
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8473 {
8474 new_return(33);
8475 }
8476
8477
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8478 {
8479 new_return(34);
8480 }
8481
8482
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8483 {
8484 new_return(35);
8485 }
8486
8487
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8488 {
8489 new_return(36);
8490 }
8491
8492
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8493 {
8494 new_return(37);
8495 }
8496
8497
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8498 {
8499 new_return(38);
8500 }
8501
8502
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8503 {
8504
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8505 {
8506 new_return(39);
8507 }
8508 9216 }
8509
8510
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8511 {
8512 new_return(40);
8513 }
8514
8515
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8516 {
8517 new_return(41);
8518 }
8519
8520
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8521 {
8522 new_return(42);
8523 }
8524
8525
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8526 {
8527 new_return(43);
8528 }
8529
8530
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8531 {
8532 new_return(44);
8533 }
8534
8535
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8536 {
8537 new_return(45);
8538 }
8539
8540
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8541 {
8542 new_return(46);
8543 }
8544
8545
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8546 {
8547 new_return(47);
8548 }
8549
8550
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8551 {
8552 new_return(48);
8553 }
8554
8555
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8556 {
8557 new_return(48);
8558 }
8559
8560 //New itemdata vars -Z
8561 //! version 27
8562
8563
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].useweapon,f))
8564 {
8565 new_return(49);
8566 }
8567
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usedefence,f))
8568 {
8569 new_return(50);
8570 }
8571
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8572 {
8573 new_return(51);
8574 }
8575
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8576 {
8577 new_return(52);
8578 }
8579
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8580
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8581 {
8582 new_return(53);
8583 }
8584 46080 }
8585 //version 28
8586
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8587 {
8588 new_return(54);
8589 }
8590
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < INITIAL_D; q++ )
8591 {
8592
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8593 {
8594 new_return(55);
8595 }
8596 36864 }
8597
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8598 {
8599
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8600 {
8601 new_return(56);
8602 }
8603 9216 }
8604
8605
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8606 {
8607 new_return(57);
8608 }
8609
8610
8611
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8612 {
8613 new_return(58);
8614 }
8615
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8616 {
8617 new_return(59);
8618 }
8619
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8620 {
8621 new_return(60);
8622 }
8623
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8624 {
8625 new_return(61);
8626 }
8627
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8628 {
8629 new_return(62);
8630 }
8631
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8632 {
8633 new_return(63);
8634 }
8635
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8636 {
8637 new_return(64);
8638 }
8639
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8640 {
8641 new_return(65);
8642 }
8643
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8644 {
8645 new_return(66);
8646 }
8647
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8648 {
8649 new_return(67);
8650 }
8651
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8652 {
8653 new_return(68);
8654 }
8655
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8656 {
8657 new_return(69);
8658 }
8659
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8660 {
8661 new_return(70);
8662 }
8663
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8664 {
8665 new_return(71);
8666 }
8667
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].weaponscript,f))
8668 {
8669 new_return(72);
8670 }
8671
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8672 {
8673 new_return(73);
8674 }
8675
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8676 {
8677
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8678 {
8679 new_return(74);
8680 }
8681 9216 }
8682
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8683 {
8684 new_return(75);
8685 }
8686
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8687 {
8688 new_return(76);
8689 }
8690
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8691 {
8692 new_return(77);
8693 }
8694
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8695 {
8696 new_return(78);
8697 }
8698
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8699 {
8700 new_return(79);
8701 }
8702
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8703 {
8704 new_return(80);
8705 }
8706
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8707 {
8708 new_return(81);
8709 }
8710
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8711 {
8712 new_return(82);
8713 }
8714
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8715 {
8716 new_return(83);
8717 }
8718
8719
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8720 {
8721
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8722 {
8723 new_return(84);
8724 }
8725 9216 }
8726
8727 //InitD[] labels
8728
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8729 {
8730
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8731 {
8732
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8733 {
8734 new_return(85);
8735 }
8736 2396160 }
8737
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8738 {
8739
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8740 {
8741 new_return(86);
8742 }
8743 2396160 }
8744
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8745 {
8746
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8747 {
8748 new_return(87);
8749 }
8750 2396160 }
8751
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8752 {
8753 new_return(88);
8754 }
8755 36864 }
8756
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8757 {
8758
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8759 {
8760 new_return(89);
8761 }
8762
8763 9216 }
8764
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8765 {
8766 new_return(90);
8767 }
8768
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8769 {
8770 new_return(91);
8771 }
8772
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 std::string dispname(itemsbuf[i].display_name);
8773
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_putcstr(dispname,f))
8774 new_return(92);
8775
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 23040 times.
27648 for(int q = 0; q < WPNSPR_MAX; ++q)
8776 {
8777
2/4
✓ Branch 0 taken 23040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23040 times.
✗ Branch 3 not taken.
23040 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8778 new_return(93);
8779
2/4
✓ Branch 0 taken 23040 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23040 times.
23040 if(!p_putc(itemsbuf[i].light_rads[q], f))
8780 new_return(94);
8781 23040 }
8782
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_putc(itemsbuf[i].pickup_litems, f))
8783 new_return(95);
8784
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8785 new_return(96);
8786 4608 }
8787
8788
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8789 {
8790 9 section_size=writesize;
8791 9 }
8792 18 }
8793
8794
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8795 {
8796 char ebuf[80];
8797 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8798 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8799 }
8800
8801 9 new_return(0);
8802 }
8803
8804 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8805 {
8806 //these are here to bypass compiler warnings about unused arguments
8807 9 Header=Header;
8808
8809 9 dword section_id=ID_WEAPONS;
8810 9 dword section_version=V_WEAPONS;
8811 9 dword section_size = 0;
8812
8813 //section id
8814
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8815 {
8816 new_return(1);
8817 }
8818
8819 //section version info
8820
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8821 {
8822 new_return(2);
8823 }
8824
8825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8826 {
8827 new_return(3);
8828 }
8829
8830
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8831 {
8832 18 fake_pack_writing=(writecycle==0);
8833
8834 //section size
8835
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8836 {
8837 new_return(4);
8838 }
8839
8840 18 writesize=0;
8841
8842 //finally... section data
8843
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8844 {
8845 new_return(5);
8846 }
8847
8848
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8849 {
8850
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8851 {
8852 new_return(5);
8853 }
8854 4608 }
8855
8856
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8857 {
8858
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8859 {
8860 new_return(7);
8861 }
8862
8863
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8864 {
8865 new_return(8);
8866 }
8867
8868
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8869 {
8870 new_return(9);
8871 }
8872
8873
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8874 {
8875 new_return(10);
8876 }
8877
8878
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8879 {
8880 new_return(11);
8881 }
8882
8883
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8884 {
8885 new_return(12);
8886 }
8887
8888
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8889 {
8890 new_return(12);
8891 }
8892 4608 }
8893
8894
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8895 {
8896 9 section_size=writesize;
8897 9 }
8898 18 }
8899
8900
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8901 {
8902 char ebuf[80];
8903 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8904 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8905 }
8906
8907 9 new_return(0);
8908 }
8909
8910 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8911 {
8912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8913 return qe_invalid;
8914
8915 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8916 12784 bool is_0x80_screen = j >= 0x80;
8917
8918
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8919 return qe_invalid;
8920
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8921 4404 return qe_OK;
8922 //Calculate what needs writing
8923 8380 uint32_t scr_has_flags = 0;
8924
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8925
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8926 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8927
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8928 446 scr_has_flags |= SCRHAS_ITEM;
8929
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8930 28 scr_has_flags |= SCRHAS_TWARP;
8931
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8932 {
8933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32706 times.
65588 if(screen.tilewarptype[q]
8934
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8935
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8936 {
8937 176 scr_has_flags |= SCRHAS_TWARP;
8938 176 break;
8939 }
8940 32706 }
8941
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 8344 times.
✗ Branch 3 not taken.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8942
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8943 36 scr_has_flags |= SCRHAS_SWARP;
8944
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8945 {
8946
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 16298 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8947
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8948
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8949 {
8950 4270 scr_has_flags |= SCRHAS_SWARP;
8951 4270 break;
8952 }
8953 16298 }
8954
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8955 44 scr_has_flags |= SCRHAS_WARPRET;
8956
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8957 {
8958
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 30208 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8959 {
8960 784 scr_has_flags |= SCRHAS_WARPRET;
8961 784 break;
8962 }
8963 30208 }
8964
8965
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8966 scr_has_flags |= SCRHAS_LAYERS;
8967
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8968 {
8969
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 44532 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8970
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8971 {
8972 966 scr_has_flags |= SCRHAS_LAYERS;
8973 966 break;
8974 }
8975 44532 }
8976
8977
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8978 10 scr_has_flags |= SCRHAS_MAZE;
8979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8980 scr_has_flags |= SCRHAS_MAZE;
8981
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8982 {
8983
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8984 {
8985 scr_has_flags |= SCRHAS_MAZE;
8986 break;
8987 }
8988 33480 }
8989
8990
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8991
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8992
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8993 2968 scr_has_flags |= SCRHAS_D_S_U;
8994
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8995 {
8996
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8997 {
8998 5212 scr_has_flags |= SCRHAS_D_S_U;
8999 5212 break;
9000 }
9001 800 }
9002
9003
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
9004
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
9005
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
9006
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
9007
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
9008
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
9009 8380 scr_has_flags |= SCRHAS_FLAGS;
9010
9011
2/2
✓ Branch 0 taken 8322 times.
✓ Branch 1 taken 58 times.
8380 if(screen.pattern)
9012 58 scr_has_flags |= SCRHAS_ENEMY;
9013
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
9014 {
9015
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
9016 {
9017 1014 scr_has_flags |= SCRHAS_ENEMY;
9018 1014 break;
9019 }
9020 73086 }
9021
9022
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8346 times.
16726 if(screen.noreset || screen.nocarry
9023
3/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8346 times.
✓ Branch 3 taken 34 times.
8380 || screen.nextmap || screen.nextscr)
9024 34 scr_has_flags |= SCRHAS_CARRY;
9025
9026
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
9027 22 scr_has_flags |= SCRHAS_SCRIPT;
9028
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
9029 {
9030
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
9031 {
9032 scr_has_flags |= SCRHAS_SCRIPT;
9033 break;
9034 }
9035 66864 }
9036
9037
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
9038 {
9039
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
9040
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9041
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9042 {
9043 3076 scr_has_flags |= SCRHAS_SECRETS;
9044 3076 break;
9045 }
9046 680916 }
9047
9048
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9049 {
9050
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9051
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9052 {
9053 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9054 5360 break;
9055 }
9056 568532 }
9057
9058
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9059
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9060
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9061 || screen.timedwarptics || screen.screen_midi != -1
9062 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9063 8380 scr_has_flags |= SCRHAS_MISC;
9064
9065
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9066 return qe_invalid;
9067
9068 //Write stuff
9069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9070 {
9071
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9072 return qe_invalid;
9073
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9074 return qe_invalid;
9075
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9076 return qe_invalid;
9077
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9078 return qe_invalid;
9079
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9080 return qe_invalid;
9081
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9082 return qe_invalid;
9083
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9084 return qe_invalid;
9085 8380 }
9086
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9087 {
9088
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9089 return qe_invalid;
9090
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9091 return qe_invalid;
9092
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9093 return qe_invalid;
9094
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9095 return qe_invalid;
9096 446 }
9097
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9098 {
9099
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9100 return qe_invalid;
9101 4374 }
9102
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9103 {
9104
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9105 {
9106
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9107 return qe_invalid;
9108 816 }
9109
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9110 {
9111
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9112 return qe_invalid;
9113 816 }
9114
9115
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9116 {
9117
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9118 return qe_invalid;
9119 816 }
9120
9121
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9122 return qe_invalid;
9123 204 }
9124
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9125 {
9126
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9127 {
9128
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9129 return qe_invalid;
9130 17224 }
9131
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9132 {
9133
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9134 return qe_invalid;
9135 17224 }
9136
9137
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9138 {
9139
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9140 return qe_invalid;
9141 17224 }
9142
9143
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9144 return qe_invalid;
9145
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9146 return qe_invalid;
9147 4306 }
9148
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9149 {
9150
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9151 {
9152
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9153 return qe_invalid;
9154 3312 }
9155
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9156 {
9157
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9158 return qe_invalid;
9159 3312 }
9160
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9161 return qe_invalid;
9162
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9163 return qe_invalid;
9164 828 }
9165
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9166 {
9167
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9168 {
9169
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9170 return qe_invalid;
9171 5796 }
9172
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9173 {
9174
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9175 return qe_invalid;
9176 5796 }
9177
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9178 {
9179
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9180 return qe_invalid;
9181 5796 }
9182
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9183 return qe_invalid;
9184
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9185 return qe_invalid;
9186 966 }
9187
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9188 {
9189
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9190 {
9191
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9192 return qe_invalid;
9193 40 }
9194
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9195 return qe_invalid;
9196
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9197 return qe_invalid;
9198 10 }
9199
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9200 {
9201
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9202 return qe_invalid;
9203
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9204 {
9205
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9206 return qe_invalid;
9207 32720 }
9208
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9209 return qe_invalid;
9210
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9211 return qe_invalid;
9212
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9213 return qe_invalid;
9214
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9215 return qe_invalid;
9216 8180 }
9217
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9218 {
9219
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9220 return qe_invalid;
9221
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9222 return qe_invalid;
9223
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9224 return qe_invalid;
9225
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9226 return qe_invalid;
9227
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9228 return qe_invalid;
9229
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9230 return qe_invalid;
9231
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9232 return qe_invalid;
9233
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9234 return qe_invalid;
9235
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9236 return qe_invalid;
9237
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9238 return qe_invalid;
9239
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9240 return qe_invalid;
9241 1294 }
9242
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9243 {
9244
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9245 {
9246
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9247 return qe_invalid;
9248 10720 }
9249
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9250 return qe_invalid;
9251 1072 }
9252
2/2
✓ Branch 0 taken 8346 times.
✓ Branch 1 taken 34 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9253 {
9254
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_iputw(screen.noreset,f))
9255 return qe_invalid;
9256
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_iputw(screen.nocarry,f))
9257 return qe_invalid;
9258
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_putc(screen.nextmap,f))
9259 return qe_invalid;
9260
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_putc(screen.nextscr,f))
9261 return qe_invalid;
9262 34 }
9263
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9264 {
9265
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9266 return qe_invalid;
9267
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9268 return qe_invalid;
9269
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9270 {
9271
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9272 return qe_invalid;
9273 176 }
9274 22 }
9275
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9276 {
9277
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9278 {
9279
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9280 return qe_invalid;
9281 393728 }
9282
9283
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9284 {
9285
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9286 return qe_invalid;
9287 393728 }
9288
9289
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9290 {
9291
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9292 return qe_invalid;
9293 393728 }
9294 3076 }
9295
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9296 {
9297
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9298 {
9299
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9300 return qe_invalid;
9301 943360 }
9302
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9303 {
9304
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9305 return qe_invalid;
9306 943360 }
9307
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9308 {
9309
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9310 return qe_invalid;
9311 943360 }
9312 5360 }
9313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9314 {
9315
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9316 return qe_invalid;
9317
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9318 return qe_invalid;
9319
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9320 return qe_invalid;
9321
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9322 return qe_invalid;
9323
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9324 return qe_invalid;
9325
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9326 return qe_invalid;
9327
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9328 return qe_invalid;
9329
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9330 return qe_invalid;
9331
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9332 return qe_invalid;
9333
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_show,f))
9334 return qe_invalid;
9335
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9336 return qe_invalid;
9337 8380 }
9338
9339 8380 dword numffc = screen.numFFC();
9340
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9341 return qe_invalid;
9342
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9343 {
9344 245678 ffcdata const& tempffc = screen.ffcs[k];
9345
9346
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9347 return qe_invalid;
9348
9349
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9350 243364 continue;
9351
9352
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9353 return qe_invalid;
9354
9355
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9356 return qe_invalid;
9357
9358
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9359 return qe_invalid;
9360
9361
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9362 return qe_invalid;
9363
9364
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9365 return qe_invalid;
9366
9367
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9368 return qe_invalid;
9369
9370
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9371 return qe_invalid;
9372
9373
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9374 return qe_invalid;
9375
9376
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9377 return qe_invalid;
9378
9379
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9380 return qe_invalid;
9381
9382
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9383 return qe_invalid;
9384
9385
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9386 return qe_invalid;
9387
9388
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9389 return qe_invalid;
9390
9391
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9392 return qe_invalid;
9393
9394
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9395 return qe_invalid;
9396
9397
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9398 {
9399
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9400 return qe_invalid;
9401 18512 }
9402
9403
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9404 return qe_invalid;
9405 2314 }
9406
9407
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9408 return qe_invalid;
9409
9410 8380 return qe_OK;
9411 12784 }
9412
9413 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9414 {
9415 9 dword section_id=ID_MAPS;
9416 9 dword section_version=V_MAPS;
9417 9 dword section_size = 0;
9418
9419 //section id
9420
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9421 {
9422 new_return(1);
9423 }
9424
9425 //section version info
9426
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9427 {
9428 new_return(2);
9429 }
9430
9431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9432 {
9433 new_return(3);
9434 }
9435
9436
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9437 {
9438 18 fake_pack_writing=(writecycle==0);
9439
9440 //section size
9441
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9442 {
9443 new_return(4);
9444 }
9445
9446 18 writesize=0;
9447
9448
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9449 {
9450 new_return(5);
9451 }
9452 18 map_autolayers.resize(map_count*6);
9453
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9454 {
9455 100 byte valid = 0;
9456
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9457 {
9458
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9459 break;
9460 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9461
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9462 {
9463 94 valid = 1;
9464 94 break;
9465 }
9466 1188 }
9467
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9468 {
9469 new_return(6);
9470 }
9471
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9472
9473 { //per-map info
9474
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9475 {
9476 564 size_t ind = i*6+q;
9477
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(map_autolayers[ind],f))
9478 new_return(7);
9479 564 }
9480
9481
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9482 {
9483
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9484 {
9485
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9486 {
9487 new_return(8);
9488 }
9489 6016 }
9490 752 }
9491 }
9492
9493
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9494 12784 writemapscreen(f,i,j);
9495 94 }
9496
9497
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9498 {
9499 9 section_size=writesize;
9500 9 }
9501 18 }
9502
9503
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9504 {
9505 char ebuf[80];
9506 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9507 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9508 }
9509
9510 9 new_return(0);
9511 }
9512
9513 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9514 {
9515 //Check what needs writing
9516 byte combo_has_flags = 0;
9517 1029676 for(auto q = 0; q < 8; ++q)
9518 {
9519 2059352 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9520 1029676 || (q < 4 && tmp_cmb.attributes[q]))
9521 {
9522 combo_has_flags |= CHAS_ATTRIB;
9523 break;
9524 }
9525 1029676 }
9526
3/4
✓ Branch 0 taken 258514 times.
✓ Branch 1 taken 258514 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 258446 times.
258446 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9527
3/4
✓ Branch 0 taken 258512 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258512 times.
✗ Branch 3 not taken.
258514 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9528
3/4
✓ Branch 0 taken 258510 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258512 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9529
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9530
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9531
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9532
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9533
4/4
✓ Branch 0 taken 258448 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 258446 times.
✓ Branch 3 taken 2 times.
258510 || tmp_cmb.trigchange || tmp_cmb.trigprox
9534
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9535
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9536
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9537
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9538
1/2
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
258446 || tmp_cmb.exdoor_dir > -1
9539
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9540
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9541
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9542
1/2
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
258446 || tmp_cmb.trigdmlevel > -1
9543
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9544
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9545
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9546
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9547
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9548
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9549
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9550 258582 combo_has_flags |= CHAS_TRIG;
9551
2/2
✓ Branch 0 taken 775338 times.
✓ Branch 1 taken 258446 times.
1033784 else for(int q = 0; q < 3; ++q)
9552
1/2
✓ Branch 0 taken 775338 times.
✗ Branch 1 not taken.
775338 if(tmp_cmb.trigtint[q])
9553 combo_has_flags |= CHAS_TRIG;
9554
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 258400 times.
✓ Branch 2 taken 258102 times.
✓ Branch 3 taken 526 times.
517028 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9555 516502 combo_has_flags |= CHAS_FLAG;
9556
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 250982 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 243350 times.
✓ Branch 5 taken 12086 times.
232088 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9557
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9558
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9559 514874 combo_has_flags |= CHAS_ANIM;
9560
4/4
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 218646 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
40260 if(tmp_cmb.script || tmp_cmb.label.size())
9561 218652 combo_has_flags |= CHAS_SCRIPT;
9562
2/2
✓ Branch 0 taken 2071200 times.
✓ Branch 1 taken 258900 times.
2330100 else for(auto q = 0; q < 8; ++q)
9563 {
9564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2071200 times.
2071200 if(tmp_cmb.initd[q])
9565 {
9566 combo_has_flags |= CHAS_SCRIPT;
9567 break;
9568 }
9569 2071200 }
9570
6/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 300648 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 218646 times.
✓ Branch 5 taken 42254 times.
653944 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9571
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9572 519806 combo_has_flags |= CHAS_BASIC;
9573
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 134130 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
383664 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9574
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9575
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9576
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9577
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9578
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9579
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftlightrad || tmp_cmb.liftlightshape
9580
1/2
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
258896 || tmp_cmb.lift_parent_item)
9581 393028 combo_has_flags |= CHAS_LIFT;
9582
3/4
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 134122 times.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
649734 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9583
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9584
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9585
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9586
2/4
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning)
9587 393028 combo_has_flags |= CHAS_GENERAL;
9588
9589
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 134122 times.
393028 if(!p_putc(combo_has_flags,f))
9590 {
9591 134122 return 50;
9592 }
9593
2/2
✓ Branch 0 taken 82514 times.
✓ Branch 1 taken 176392 times.
258906 if(!combo_has_flags) return 0; //Valid, done reading
9594 //Write the combo
9595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82514 times.
82514 if(combo_has_flags&CHAS_BASIC)
9596 {
9597
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9598 return 6;
9599
9600
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9601 return 7;
9602
9603
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9604 return 8;
9605
9606
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9607 return 9;
9608
9609
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9610 return 15;
9611
9612
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9613 return 10;
9614 82514 }
9615
2/2
✓ Branch 0 taken 82508 times.
✓ Branch 1 taken 6 times.
82514 if(combo_has_flags&CHAS_SCRIPT)
9616 {
9617 6 p_putcstr(tmp_cmb.label, f);
9618
9619
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9620 return 26;
9621
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9623 return 27;
9624 6 }
9625
2/2
✓ Branch 0 taken 54340 times.
✓ Branch 1 taken 28174 times.
82514 if(combo_has_flags&CHAS_ANIM)
9626 {
9627
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9628 return 11;
9629
9630
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9631 return 12;
9632
9633
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9634 return 13;
9635
9636
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9637 return 14;
9638
9639
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9640 return 16;
9641
9642
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9643 return 18;
9644
9645
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9646 return 19;
9647 28174 }
9648
2/2
✓ Branch 0 taken 79324 times.
✓ Branch 1 taken 3190 times.
82514 if(combo_has_flags&CHAS_ATTRIB)
9649 {
9650
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9651
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12760 times.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9652 return 20;
9653
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25520 times.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9655 return 25;
9656
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25520 times.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9658 return 32;
9659 3190 }
9660
2/2
✓ Branch 0 taken 82216 times.
✓ Branch 1 taken 298 times.
82514 if(combo_has_flags&CHAS_FLAG)
9661 {
9662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9663 return 21;
9664
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9665 return 33;
9666 298 }
9667
2/2
✓ Branch 0 taken 82054 times.
✓ Branch 1 taken 460 times.
82514 if(combo_has_flags&CHAS_TRIG)
9668 {
9669
2/2
✓ Branch 0 taken 2760 times.
✓ Branch 1 taken 460 times.
3220 for ( int32_t q = 0; q < 6; q++ )
9670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2760 times.
2760 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9671 return 22;
9672
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.triggerlevel,f))
9673 return 23;
9674
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.triggerbtn,f))
9675 return 34;
9676
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.triggeritem,f))
9677 return 35;
9678
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigtimer,f))
9679 return 36;
9680
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigsfx,f))
9681 return 37;
9682
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.trigchange,f))
9683 return 38;
9684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_cmb.trigprox,f))
9685 return 39;
9686
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigctr,f))
9687 return 40;
9688
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.trigctramnt,f))
9689 return 41;
9690
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.triglbeam,f))
9691 return 42;
9692
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigcschange,f))
9693 return 43;
9694
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.spawnitem,f))
9695 return 44;
9696
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.spawnenemy,f))
9697 return 45;
9698
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.exstate,f))
9699 return 46;
9700
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.spawnip,f))
9701 return 47;
9702
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigcopycat,f))
9703 return 48;
9704
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigcooldown,f))
9705 return 49;
9706
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.prompt_cid,f))
9707 return 50;
9708
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.prompt_cs,f))
9709 return 51;
9710
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.prompt_x,f))
9711 return 52;
9712
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.prompt_y,f))
9713 return 53;
9714
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_lstate,f))
9715 return 69;
9716
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_gstate,f))
9717 return 70;
9718
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.trig_statetime,f))
9719 return 71;
9720
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_genscr,f))
9721 return 72;
9722
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_group,f))
9723 return 76;
9724
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_group_val,f))
9725 return 77;
9726
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.exdoor_dir,f))
9727 return 89;
9728
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.exdoor_ind,f))
9729 return 90;
9730
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_levelitems,f))
9731 return 91;
9732
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9733 return 92;
9734
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9735
1/2
✓ Branch 0 taken 1380 times.
✗ Branch 1 not taken.
1380 if(!p_iputw(tmp_cmb.trigtint[q],f))
9736 return 93;
9737
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9738 return 94;
9739
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9740 return 95;
9741
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigquaketime,f))
9742 return 96;
9743
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigwavytime,f))
9744 return 97;
9745
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9746 return 98;
9747
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9748 return 99;
9749
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9750 return 100;
9751
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9752 return 101;
9753
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_pushtime,f))
9754 return 102;
9755
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9756 return 103;
9757 460 }
9758
2/2
✓ Branch 0 taken 82504 times.
✓ Branch 1 taken 10 times.
82514 if(combo_has_flags&CHAS_LIFT)
9759 {
9760
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(tmp_cmb.liftcmb,f))
9761 return 54;
9762
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftcs,f))
9763 return 55;
9764
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(tmp_cmb.liftundercmb,f))
9765 return 56;
9766
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftundercs,f))
9767 return 57;
9768
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftdmg,f))
9769 return 58;
9770
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftlvl,f))
9771 return 59;
9772
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftitm,f))
9773 return 60;
9774
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftflags,f))
9775 return 61;
9776
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftgfx,f))
9777 return 62;
9778
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftsprite,f))
9779 return 63;
9780
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftsfx,f))
9781 return 64;
9782
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9783 return 65;
9784
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9785 return 66;
9786
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.lifthei,f))
9787 return 67;
9788
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.lifttime,f))
9789 return 68;
9790
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.lift_parent_item,f))
9791 return 78;
9792
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftlightrad,f))
9793 return 96;
9794
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftlightshape,f))
9795 return 97;
9796 10 }
9797
2/2
✓ Branch 0 taken 80314 times.
✓ Branch 1 taken 2200 times.
82514 if(combo_has_flags&CHAS_GENERAL)
9798 {
9799
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9800 return 73;
9801
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9802 return 74;
9803
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9804 return 75;
9805
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9806 return 79;
9807
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9808 return 80;
9809
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9810 return 81;
9811
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9812 return 82;
9813
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9814 return 83;
9815
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9816 return 84;
9817
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9818 return 85;
9819
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9820 return 86;
9821
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9822 return 87;
9823
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9824 return 88;
9825
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9826 return 89;
9827
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9828 return 90;
9829
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9830 return 91;
9831
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9832 return 92;
9833
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9834 return 93;
9835
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9836 return 94;
9837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9838 return 95;
9839 2200 }
9840 82514 return 0;
9841 393028 }
9842
9843 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9844 {
9845 //these are here to bypass compiler warnings about unused arguments
9846 9 version=version;
9847 9 build=build;
9848
9849 word combos_used;
9850 9 dword section_id=ID_COMBOS;
9851 9 dword section_version=V_COMBOS;
9852 // dword section_size=0;
9853 9 combos_used = count_combos()-start_combo;
9854
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9855
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9856 9 dword section_size = 0;
9857
9858 //section id
9859
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9860 {
9861 new_return(1);
9862 }
9863
9864 //section version info
9865
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9866 {
9867 new_return(2);
9868 }
9869
9870
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9871 {
9872 new_return(3);
9873 }
9874
9875
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9876 {
9877 18 fake_pack_writing=(writecycle==0);
9878
9879 //section size
9880
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9881 {
9882 new_return(4);
9883 }
9884
9885 18 writesize=0;
9886
9887 //finally... section data
9888 18 combos_used=count_combos()-start_combo;
9889
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9890
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9891
9892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9893 {
9894 new_return(5);
9895 }
9896
9897 18 size_t end_combo = start_combo+combos_used;
9898
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9899 {
9900 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9901
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9902 258906 }
9903
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9904 {
9905 9 section_size=writesize;
9906 9 }
9907 18 }
9908
9909
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9910 {
9911 char ebuf[80];
9912 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9913 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9914 }
9915
9916 9 new_return(0);
9917 9 }
9918
9919 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9920 {
9921 //these are here to bypass compiler warnings about unused arguments
9922 9 version=version;
9923 9 build=build;
9924
9925 9 dword section_id=ID_COMBOALIASES;
9926 9 dword section_version=V_COMBOALIASES;
9927 9 dword section_size=0;
9928
9929 //section id
9930
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9931 {
9932 new_return(1);
9933 }
9934
9935 //section version info
9936
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9937 {
9938 new_return(2);
9939 }
9940
9941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9942 {
9943 new_return(3);
9944 }
9945
9946
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9947 {
9948 18 fake_pack_writing=(writecycle==0);
9949
9950 //section size
9951
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9952 {
9953 new_return(4);
9954 }
9955
9956 18 writesize=0;
9957
9958 //finally... section data
9959
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9960 {
9961
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9962 {
9963 new_return(5);
9964 }
9965
9966
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9967 {
9968 new_return(6);
9969 }
9970
9971 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9972
9973
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9974 {
9975 new_return(7);
9976 }
9977
9978
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9979 {
9980 new_return(8);
9981 }
9982
9983
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
9984 {
9985 new_return(9);
9986 }
9987
9988
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9989 {
9990
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
9991 {
9992 new_return(10);
9993 }
9994 149596 }
9995
9996
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9997 {
9998
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
9999 {
10000 new_return(11);
10001 }
10002 149596 }
10003 147456 }
10004
10005 //Combo pools!
10006 int16_t num_cpools;
10007
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10008 {
10009
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10010 {
10011 2 ++num_cpools;
10012 2 break;
10013 }
10014 147450 }
10015
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10016
10017
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10018 {
10019 new_return(12);
10020 }
10021
10022
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10023 {
10024 6 combo_pool const& pool = combo_pools[cp];
10025 6 int32_t num_combos = pool.combos.size();
10026
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10027 {
10028 new_return(13);
10029 }
10030
10031
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10032 {
10033 26 cpool_entry const& entry = pool.combos.at(q);
10034
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10035 {
10036 new_return(14);
10037 }
10038
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10039 {
10040 new_return(15);
10041 }
10042
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10043 {
10044 new_return(16);
10045 }
10046 26 }
10047 6 }
10048
10049 //Autocombos!
10050 int16_t num_cautos;
10051
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10052 {
10053
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10054 {
10055 ++num_cautos;
10056 break;
10057 }
10058 147456 }
10059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10060
10061
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10062 {
10063 new_return(17);
10064 }
10065
10066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10067 {
10068 combo_auto const& cauto = combo_autos[ca];
10069 if (!p_putc(cauto.getType(), f))
10070 {
10071 new_return(18);
10072 }
10073 if (!p_iputl(cauto.getIconDisplay(), f))
10074 {
10075 new_return(19);
10076 }
10077 if (!p_iputl(cauto.getEraseCombo(), f))
10078 {
10079 new_return(20);
10080 }
10081 if (!p_putc(cauto.getFlags(), f))
10082 {
10083 new_return(21);
10084 }
10085 if (!p_putc(cauto.getArg(), f))
10086 {
10087 new_return(22);
10088 }
10089 int32_t num_combos = cauto.combos.size();
10090 if (!p_iputl(num_combos, f))
10091 {
10092 new_return(23);
10093 }
10094
10095 for (auto q = 0; q < num_combos; ++q)
10096 {
10097 autocombo_entry const& entry = cauto.combos.at(q);
10098 if (!p_putc(entry.ctype, f))
10099 {
10100 new_return(24);
10101 }
10102 if (!p_iputl(entry.cid, f))
10103 {
10104 new_return(25);
10105 }
10106 }
10107 }
10108
10109
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10110 {
10111 9 section_size=writesize;
10112 9 }
10113 18 }
10114
10115
10116
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10117 {
10118 char ebuf[80];
10119 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10120 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10121 }
10122
10123 9 new_return(0);
10124 }
10125
10126 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10127 {
10128 //these are here to bypass compiler warnings about unused arguments
10129 9 version=version;
10130 9 build=build;
10131 9 start_cset=start_cset;
10132 9 max_csets=max_csets;
10133
10134 9 dword section_id=ID_CSETS;
10135 9 dword section_version=V_CSETS;
10136 9 int32_t palcycles = count_palcycles(&QMisc);
10137 // int32_t palcyccount = count_palcycles(&QMisc);
10138 9 dword section_size = 0;
10139
10140 //section id
10141
10142
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10143 {
10144 new_return(1);
10145 }
10146
10147 //section version info
10148
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10149 {
10150 new_return(2);
10151 }
10152
10153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10154 {
10155 new_return(3);
10156 }
10157
10158
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10159 {
10160 18 fake_pack_writing=(writecycle==0);
10161
10162 //section size
10163
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10164 {
10165 new_return(4);
10166 }
10167
10168 18 writesize=0;
10169
10170 //finally... section data
10171
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10172 {
10173 new_return(5);
10174 }
10175
10176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10177 {
10178 new_return(6);
10179 }
10180
10181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10182 {
10183 new_return(15);
10184 }
10185
10186
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10187 {
10188
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10189 {
10190
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10191 {
10192 new_return(16);
10193 }
10194 1650 }
10195
10196
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10197 {
10198
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10199 {
10200 new_return(17);
10201 }
10202 1650 }
10203
10204
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10205 {
10206
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10207 {
10208 new_return(18);
10209 }
10210 1650 }
10211 550 }
10212
10213
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10214 {
10215 9 section_size=writesize;
10216 9 }
10217 18 }
10218
10219
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10220 {
10221 char ebuf[80];
10222 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10223 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10224 }
10225
10226 9 new_return(0);
10227 }
10228
10229 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10230 {
10231 //these are here to bypass compiler warnings about unused arguments
10232 9 version=version;
10233 9 build=build;
10234 9 start_msgstr=start_msgstr;
10235 9 max_msgstrs=max_msgstrs;
10236
10237 9 dword section_id=ID_STRINGS;
10238 9 dword section_version=V_STRINGS;
10239 9 dword section_size = 0;
10240
10241 //section id
10242
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10243 {
10244 new_return(1);
10245 }
10246
10247 //section version info
10248
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10249 {
10250 new_return(2);
10251 }
10252
10253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10254 {
10255 new_return(3);
10256 }
10257
10258
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10259 {
10260 18 fake_pack_writing=(writecycle==0);
10261
10262 //section size
10263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10264 {
10265 new_return(4);
10266 }
10267
10268 18 writesize=0;
10269
10270 //finally... section data
10271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10272 {
10273 return qe_invalid;
10274 }
10275
10276
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10277 {
10278 836 int32_t sz = MsgStrings[i].s.size();
10279
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10280
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10281 {
10282 return qe_invalid;
10283 }
10284
10285 836 char const* tmpstr = MsgStrings[i].s.c_str();
10286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10287 {
10288
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10289 {
10290 return qe_invalid;
10291 }
10292 836 }
10293
10294
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10295 {
10296 return qe_invalid;
10297 }
10298
10299
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10300 {
10301 return qe_invalid;
10302 }
10303
10304
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10305 {
10306 return qe_invalid;
10307 }
10308
10309
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10310 {
10311 return qe_invalid;
10312 }
10313
10314
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10315 {
10316 return qe_invalid;
10317 }
10318
10319
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10320 {
10321 return qe_invalid;
10322 }
10323
10324
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10325 {
10326 return qe_invalid;
10327 }
10328
10329
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10330 {
10331 return qe_invalid;
10332 }
10333
10334
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10335 {
10336 return qe_invalid;
10337 }
10338
10339
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10340 {
10341 return qe_invalid;
10342 }
10343
10344
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10345 {
10346 return qe_invalid;
10347 }
10348
10349
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10350 {
10351 return qe_invalid;
10352 }
10353
10354
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10355 {
10356
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10357 {
10358 return qe_invalid;
10359 }
10360 3344 }
10361
10362
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10363 {
10364 return qe_invalid;
10365 }
10366
10367
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10368 {
10369 return qe_invalid;
10370 }
10371
10372
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10373 {
10374 return qe_invalid;
10375 }
10376
10377
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10378 {
10379 return qe_invalid;
10380 }
10381
10382
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10383 {
10384 return qe_invalid;
10385 }
10386
10387
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10388 {
10389 return qe_invalid;
10390 }
10391
10392
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10393 {
10394 return qe_invalid;
10395 }
10396
10397
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10398 {
10399 return qe_invalid;
10400 }
10401
10402
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10403 {
10404 return qe_invalid;
10405 }
10406
10407
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10408 {
10409 return qe_invalid;
10410 }
10411
10412
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10413 {
10414 return qe_invalid;
10415 }
10416 836 }
10417
10418
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10419 {
10420 9 section_size=writesize;
10421 9 }
10422 18 }
10423
10424
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10425 {
10426 char ebuf[80];
10427 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10428 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10429 }
10430
10431 9 new_return(0);
10432 9 }
10433
10434 int32_t writestrings_text(PACKFILE *f)
10435 {
10436 std::map<int32_t, int32_t> msglistcache;
10437
10438 for(int32_t index = 1; index<msg_count; index++)
10439 {
10440 for(int32_t i=1; i<msg_count; i++)
10441 {
10442 if(MsgStrings[i].listpos==index)
10443 {
10444 msglistcache[index-1]=i;
10445 break;
10446 }
10447 }
10448 }
10449
10450 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10451 {
10452 fake_pack_writing=(writecycle==0);
10453 char ebuf[32];
10454
10455 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10456
10457 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10458 {
10459 return qe_invalid;
10460 }
10461
10462 for(int32_t i=1; i<msg_count; i++)
10463 {
10464 int32_t str = msglistcache[i-1];
10465
10466 if(!str)
10467 continue;
10468
10469 if(MsgStrings[str].nextstring != 0)
10470 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10471 else
10472 sprintf(ebuf,"\n\n___%d___\n", str);
10473
10474 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10475 {
10476 return qe_invalid;
10477 }
10478
10479 std::string text = MsgStrings[str].serialize();
10480 if (!pfwrite(text.c_str(), text.size(), f))
10481 {
10482 return qe_invalid;
10483 }
10484 }
10485 }
10486
10487 new_return(0);
10488 }
10489
10490 1 int32_t writestrings_tsv(PACKFILE *f)
10491 {
10492 1 std::stringstream ss;
10493
10494
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10495
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10496
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10497
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10499
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10500
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10501
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10502
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10503
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10504
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10505
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10506
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10507
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10508
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10509
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10510
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10512
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10520 };
10521
10522
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10523 {
10524
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10525
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10526 1 break;
10527
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10528 }
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10530
10531 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10533
10534
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10535 {
10536 35 auto& msg = MsgStrings[i];
10537
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10538 {
10539
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10540
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10541
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10542 35 break;
10543
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10544
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10545
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10546 35 }
10547
10548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10549
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10550 {
10551 return qe_invalid;
10552 }
10553
10554 1 new_return(0);
10555 1 }
10556
10557 std::string parse_to_legacy_msg_str_encoding(std::string const& s);
10558
10559 void parse_strings_tsv(std::string tsv)
10560 {
10561 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10562 { "message", [](auto& msg, auto& text){ msg.setFromLegacyEncoding(parse_to_legacy_msg_str_encoding(text)); } },
10563 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10564 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10565 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10566 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10567 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10568 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10569 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10570 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10571 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10572 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10573 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10574 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10575 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10576 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10577 { "margin", [&](auto& msg, auto& text){
10578 std::vector<std::string> strs;
10579 util::split(text, strs, ' ');
10580 if (strs.size() != 4)
10581 throw std::runtime_error("margin field must have 4 components");
10582 msg.margins[0] = std::stoi(strs[0]);
10583 msg.margins[1] = std::stoi(strs[1]);
10584 msg.margins[2] = std::stoi(strs[2]);
10585 msg.margins[3] = std::stoi(strs[3]);
10586 } },
10587 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10588 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10589 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10590 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10591 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10592 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10593 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10594 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10595 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10596 };
10597
10598 std::vector<std::string> rows;
10599 util::split(tsv, rows, '\n');
10600 if (rows.size())
10601 {
10602 std::string last = rows.back();
10603 util::trimstr(last);
10604 if (last.empty())
10605 rows.pop_back();
10606 }
10607 if (rows.size() <= 1)
10608 throw std::runtime_error("missing header row");
10609
10610 std::vector<std::string> columns;
10611 util::split(rows[0], columns, '\t');
10612 for (auto name : columns)
10613 {
10614 if (!fields.contains(name))
10615 throw std::runtime_error(fmt::format("invalid field: {}", name));
10616 }
10617
10618 int start_index = 1;
10619 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10620 start_index += 1;
10621
10622 int num_strings = rows.size() - start_index + 1;
10623 if (num_strings > MAXMSGS-1)
10624 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10625
10626 std::vector<MsgStr> msgs;
10627 msgs.reserve(num_strings);
10628 for (int i = start_index; i < rows.size(); i++)
10629 {
10630 std::vector<std::string> strs;
10631 util::split(rows[i], strs, '\t');
10632 if (strs.size() != columns.size())
10633 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10634
10635 int j = 0;
10636 auto& msg = msgs.emplace_back();
10637 for (auto& name : columns)
10638 {
10639 auto& fn = fields[name];
10640 try
10641 {
10642 fn(msg, strs[j++]);
10643 }
10644 catch (std::exception& ex)
10645 {
10646 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10647 }
10648 }
10649 }
10650
10651 init_msgstrings(0, msgs.size());
10652 for (int i = 0; i < msgs.size(); i++)
10653 MsgStrings[i + 1] = msgs[i];
10654 msg_count = msgs.size();
10655 msglistcache.clear();
10656 }
10657
10658 bool isblanktile(tiledata *buf, int32_t i);
10659 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10660 {
10661 //these are here to bypass compiler warnings about unused arguments
10662 9 version=version;
10663 9 build=build;
10664
10665 int32_t tiles_used;
10666 9 dword section_id=ID_TILES;
10667 9 dword section_version=V_TILES;
10668 9 al_trace("Counting tiles used\n");
10669 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10672 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10673 9 dword section_size = 0;
10674
10675 //section id
10676
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10677 {
10678 new_return(1);
10679 }
10680
10681 //section version info
10682
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10683 {
10684 new_return(2);
10685 }
10686
10687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10688 {
10689 new_return(3);
10690 }
10691
10692
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10693 {
10694 18 fake_pack_writing=(writecycle==0);
10695
10696 //section size
10697
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10698 {
10699 new_return(4);
10700 }
10701
10702 18 writesize=0;
10703
10704 //finally... section data
10705 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10706
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10707
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10708
10709
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10710 {
10711 new_return(5);
10712 }
10713
10714
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10715 {
10716
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10717 {
10718
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10719 new_return(8);
10720 365770 }
10721 else
10722 {
10723 330614 int format = newtilebuf[start_tile+i].format;
10724
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10725 {
10726 new_return(6);
10727 }
10728
10729
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10730 {
10731 byte temp_tile[128];
10732 327742 byte *di = temp_tile;
10733 327742 byte *src = newtilebuf[start_tile+i].data;
10734
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10735 {
10736 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10737 41950976 ++di;
10738 41950976 }
10739
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10740 {
10741 new_return(7);
10742 }
10743 327742 }
10744
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10745 {
10746 new_return(7);
10747 }
10748 }
10749 696384 }
10750
10751
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10752 {
10753 9 section_size=writesize;
10754 9 }
10755 18 }
10756
10757
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10758 {
10759 char ebuf[80];
10760 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10761 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10762 }
10763
10764 9 new_return(0);
10765 }
10766
10767 /* MIDI Format
10768 section_id LONG
10769 section_version WORD
10770 section_cversion WORD
10771 section_size LONG
10772 midi_flags 32 Byte ? BITFIELD[252]
10773
10774 [
10775 title 36
10776 start 4
10777 loop_start 4
10778 loop_end 4
10779 loop 2
10780 volume 2
10781 midi *
10782 ]
10783
10784 */
10785
10786 9 int32_t writemidis(PACKFILE *f)
10787 {
10788 9 dword section_id=ID_MIDIS;
10789 9 dword section_version=V_MIDIS;
10790 9 dword section_size = 0;
10791
10792 //section id
10793
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10794 {
10795 new_return(1);
10796 }
10797
10798 //section version info
10799
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10800 {
10801 new_return(2);
10802 }
10803
10804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10805 {
10806 new_return(3);
10807 }
10808
10809
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10810 {
10811 18 fake_pack_writing=(writecycle==0);
10812
10813 //section size
10814
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10815 {
10816 new_return(4);
10817 }
10818
10819 18 writesize=0;
10820
10821 //finally... section data
10822
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10823 {
10824 new_return(5);
10825 }
10826
10827
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10828 {
10829
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10830 {
10831
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10832 {
10833 new_return(6);
10834 }
10835
10836
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10837 {
10838 new_return(7);
10839 }
10840
10841
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10842 {
10843 new_return(8);
10844 }
10845
10846
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10847 {
10848 new_return(9);
10849 }
10850
10851
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10852 {
10853 new_return(10);
10854 }
10855
10856
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10857 {
10858 new_return(11);
10859 }
10860
10861
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10862 {
10863 new_return(12);
10864 }
10865
10866 130 byte format = MFORMAT_MIDI;
10867
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10868 {
10869 new_return(13);
10870 }
10871
10872
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10873 130 }
10874 4536 }
10875
10876
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10877 {
10878 9 section_size=writesize;
10879 9 }
10880 18 }
10881
10882
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10883 {
10884 char ebuf[80];
10885 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10886 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10887 }
10888
10889 9 new_return(0);
10890 }
10891
10892 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10893 {
10894 9 dword section_id=ID_CHEATS;
10895 9 dword section_version=V_CHEATS;
10896 9 dword section_size = 0;
10897
10898 //section id
10899
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10900 {
10901 new_return(1);
10902 }
10903
10904 //section version info
10905
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10906 {
10907 new_return(2);
10908 }
10909
10910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10911 {
10912 new_return(3);
10913 }
10914
10915
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10916 {
10917 18 fake_pack_writing=(writecycle==0);
10918
10919 //section size
10920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10921 {
10922 new_return(4);
10923 }
10924
10925 18 writesize=0;
10926
10927 //finally... section data
10928
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10929 {
10930 new_return(5);
10931 }
10932
10933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10934 {
10935
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10936 {
10937 new_return(6);
10938 }
10939
10940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10941 {
10942 new_return(7);
10943 }
10944 18 }
10945
10946
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10947 {
10948 9 section_size=writesize;
10949 9 }
10950 18 }
10951
10952
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10953 {
10954 char ebuf[80];
10955 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10956 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10957 }
10958
10959 9 new_return(0);
10960 }
10961
10962 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10963 {
10964 //these are here to bypass compiler warnings about unused arguments
10965 9 Header=Header;
10966
10967 9 dword section_id=ID_GUYS;
10968 9 dword section_version=V_GUYS;
10969 9 dword section_size=0;
10970
10971 //section id
10972
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10973 {
10974 new_return(1);
10975 }
10976
10977 //section version info
10978
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10979 {
10980 new_return(2);
10981 }
10982
10983
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10984 {
10985 new_return(3);
10986 }
10987
10988
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10989 {
10990 18 fake_pack_writing=(writecycle==0);
10991
10992 //section size
10993
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10994 {
10995 new_return(4);
10996 }
10997
10998 18 writesize=0;
10999
11000 //finally... section data
11001
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11002 {
11003
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11004 {
11005 new_return(5);
11006 }
11007 9216 }
11008
11009
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11010 {
11011 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11012 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11013
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11014 {
11015 new_return(6);
11016 }
11017
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11018 {
11019 new_return(7);
11020 }
11021
11022
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11023 {
11024 new_return(8);
11025 }
11026
11027
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11028 {
11029 new_return(9);
11030 }
11031
11032
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11033 {
11034 new_return(10);
11035 }
11036
11037
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11038 {
11039 new_return(11);
11040 }
11041
11042
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11043 {
11044 new_return(12);
11045 }
11046
11047
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11048 {
11049 new_return(13);
11050 }
11051
11052
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11053 {
11054 new_return(14);
11055 }
11056
11057
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11058 {
11059 new_return(15);
11060 }
11061
11062
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11063 {
11064 new_return(16);
11065 }
11066
11067
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11068 {
11069 new_return(17);
11070 }
11071
11072
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].family,f))
11073 {
11074 new_return(18);
11075 }
11076
11077
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11078 {
11079 new_return(19);
11080 }
11081
11082
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11083 {
11084 new_return(20);
11085 }
11086
11087
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11088 {
11089 new_return(21);
11090 }
11091
11092
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11093 {
11094 new_return(22);
11095 }
11096
11097
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11098 {
11099 new_return(23);
11100 }
11101
11102
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11103 {
11104 new_return(24);
11105 }
11106
11107
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11108 {
11109 new_return(25);
11110 }
11111
11112
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11113 {
11114 new_return(26);
11115 }
11116
11117
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11118 {
11119 new_return(27);
11120 }
11121
11122
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11123 {
11124 new_return(28);
11125 }
11126
11127
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11128 {
11129 new_return(29);
11130 }
11131
11132
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11133 {
11134 new_return(30);
11135 }
11136
11137
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11138 {
11139 new_return(31);
11140 }
11141
11142
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11143 {
11144 new_return(32);
11145 }
11146
11147
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11148 {
11149 new_return(33);
11150 }
11151
11152
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11153 {
11154 new_return(34);
11155 }
11156
11157
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11158 {
11159 new_return(35);
11160 }
11161
11162
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11163 {
11164 new_return(36);
11165 }
11166
11167
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11168 {
11169 new_return(37);
11170 }
11171
11172
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11173 {
11174 new_return(38);
11175 }
11176
11177
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11178 {
11179 new_return(39);
11180 }
11181
11182
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11183 {
11184 new_return(40);
11185 }
11186
11187
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11188 {
11189 new_return(41);
11190 }
11191
11192
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11193 {
11194 new_return(42);
11195 }
11196
11197
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11198 {
11199 new_return(43);
11200 }
11201
11202
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11203 {
11204 new_return(44);
11205 }
11206
11207
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11208 {
11209 new_return(45);
11210 }
11211
11212
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11213 {
11214
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11215 {
11216 new_return(46);
11217 }
11218 175104 }
11219
11220
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11221 {
11222 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11224 //Force SFX_HIT here.
11225
11226 2048 }
11227
11228
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11229 {
11230 new_return(47);
11231 }
11232
11233
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11234 {
11235 new_return(48);
11236 }
11237
11238
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11239 {
11240 new_return(49);
11241 }
11242
11243
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11244 {
11245 new_return(50);
11246 }
11247
11248 //New 2.6 defences
11249
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11250 {
11251
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11252 {
11253 new_return(51);
11254 }
11255 202752 }
11256
11257 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11258
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11259 {
11260 new_return(52);
11261 }
11262
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11263 {
11264 new_return(53);
11265 }
11266
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11267 {
11268 new_return(54);
11269 }
11270
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11271 {
11272 new_return(55);
11273 }
11274
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11275 {
11276 new_return(56);
11277 }
11278 // These are not fixed types, but ints, so they are safe to use here.
11279
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11280 {
11281 new_return(57);
11282 }
11283
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11284 {
11285 new_return(58);
11286 }
11287
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11288 {
11289 new_return(59);
11290 }
11291
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11292 {
11293 new_return(60);
11294 }
11295
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11296 {
11297 new_return(61);
11298 }
11299
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11300 {
11301 new_return(62);
11302 }
11303
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11304 {
11305 new_return(63);
11306 }
11307
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11308 {
11309 new_return(64);
11310 }
11311
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11312 {
11313 new_return(65);
11314 }
11315
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11316 {
11317 new_return(66);
11318 }
11319
11320
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11321 {
11322
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11323 {
11324 new_return(67);
11325 }
11326 92160 }
11327
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11328 {
11329 new_return(68);
11330 }
11331 //misc 16->31
11332
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11333 {
11334 new_return(69);
11335 }
11336
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11337 {
11338 new_return(70);
11339 }
11340
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11341 {
11342 new_return(71);
11343 }
11344
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11345 {
11346 new_return(72);
11347 }
11348
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11349 {
11350 new_return(73);
11351 }
11352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11353 {
11354 new_return(74);
11355 }
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11357 {
11358 new_return(75);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11361 {
11362 new_return(76);
11363 }
11364
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11365 {
11366 new_return(77);
11367 }
11368
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11369 {
11370 new_return(78);
11371 }
11372
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11373 {
11374 new_return(79);
11375 }
11376
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11377 {
11378 new_return(80);
11379 }
11380
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11381 {
11382 new_return(81);
11383 }
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11385 {
11386 new_return(82);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11389 {
11390 new_return(83);
11391 }
11392
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11393 {
11394 new_return(84);
11395 }
11396
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11397 {
11398 new_return(85);
11399 }
11400
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11401 {
11402
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11403 {
11404 new_return(86);
11405 }
11406 294912 }
11407
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11408 {
11409
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11410 {
11411 new_return(87);
11412 }
11413 294912 }
11414
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11415 {
11416 new_return(88);
11417 }
11418
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11419 {
11420
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11421 {
11422 new_return(89);
11423 }
11424 73728 }
11425
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11426 {
11427
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11428 {
11429 new_return(90);
11430 }
11431 18432 }
11432
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11433 {
11434 new_return(91);
11435 }
11436 //somehow forgot these in the older builds -Z
11437
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11438 {
11439 new_return(92);
11440 }
11441
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11442 {
11443 new_return(93);
11444 }
11445
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11446 {
11447 new_return(94);
11448 }
11449
11450 //Enemy Editor InitD[] labels
11451
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11452 {
11453
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11454 {
11455
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11456 {
11457 new_return(95);
11458 }
11459 4792320 }
11460
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11461 {
11462
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11463 {
11464 new_return(96);
11465 }
11466 4792320 }
11467 73728 }
11468
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weaponscript,f))
11469 {
11470 new_return(97);
11471 }
11472 //eweapon initD
11473
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11474 {
11475
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11476 {
11477 new_return(98);
11478 }
11479 73728 }
11480
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11481 new_return(99);
11482
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11483 new_return(100);
11484
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11485 new_return(101);
11486
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11487 new_return(102);
11488
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].wunblockable, f))
11489 new_return(103);
11490
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].wmoveflags, f))
11491 new_return(104);
11492
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weapoverrideFLAGS, f))
11493 new_return(105);
11494
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_tilew, f))
11495 new_return(106);
11496
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_tileh, f))
11497 new_return(107);
11498
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hxsz, f))
11499 new_return(108);
11500
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hysz, f))
11501 new_return(109);
11502
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hzsz, f))
11503 new_return(110);
11504
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hxofs, f))
11505 new_return(111);
11506
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hyofs, f))
11507 new_return(112);
11508
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_xofs, f))
11509 new_return(113);
11510
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_yofs, f))
11511 new_return(114);
11512
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].wstep, f))
11513 new_return(115);
11514
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 9216 times.
55296 for(int32_t q = 0; q < WPNSPR_MAX; ++q)
11515 {
11516
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if (!p_iputw(guysbuf[i].burnsprs[q], f))
11517 new_return(116);
11518
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if (!p_iputw(guysbuf[i].light_rads[q], f))
11519 new_return(117);
11520 46080 }
11521
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11522 new_return(118);
11523 9216 }
11524
11525
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11526 {
11527 9 section_size=writesize;
11528 9 }
11529 18 }
11530
11531
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11532 {
11533 char ebuf[80];
11534 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11535 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11536 }
11537
11538 9 new_return(0);
11539 }
11540
11541 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11542 {
11543 //these are here to bypass compiler warnings about unused arguments
11544 9 Header=Header;
11545
11546 9 dword section_id=ID_HEROSPRITES;
11547 9 dword section_version=V_HEROSPRITES;
11548 9 dword section_size=0;
11549
11550 //section id
11551
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11552 {
11553 new_return(1);
11554 }
11555
11556 //section version info
11557
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11558 {
11559 new_return(2);
11560 }
11561
11562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11563 {
11564 new_return(3);
11565 }
11566
11567
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11568 {
11569 18 fake_pack_writing=(writecycle==0);
11570
11571 //section size
11572
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11573 {
11574 new_return(4);
11575 }
11576
11577 18 writesize=0;
11578
11579 //finally... section data
11580
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11581 {
11582
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11583 {
11584 new_return(5);
11585 }
11586
11587
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11588 {
11589 new_return(5);
11590 }
11591
11592
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11593 {
11594 new_return(5);
11595 }
11596 72 }
11597
11598
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11599 {
11600
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11601 {
11602 new_return(6);
11603 }
11604
11605
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11606 {
11607 new_return(6);
11608 }
11609
11610
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11611 {
11612 new_return(6);
11613 }
11614 72 }
11615
11616
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11617 {
11618
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11619 {
11620 new_return(7);
11621 }
11622
11623
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11624 {
11625 new_return(7);
11626 }
11627
11628
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11629 {
11630 new_return(7);
11631 }
11632 72 }
11633
11634
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11635 {
11636
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11637 {
11638 new_return(8);
11639 }
11640
11641
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11642 {
11643 new_return(8);
11644 }
11645
11646
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11647 {
11648 new_return(8);
11649 }
11650 72 }
11651
11652
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11653 {
11654
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11655 {
11656 new_return(8);
11657 }
11658
11659
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11660 {
11661 new_return(8);
11662 }
11663
11664
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11665 {
11666 new_return(8);
11667 }
11668 72 }
11669
11670
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11671 {
11672
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11673 {
11674 new_return(9);
11675 }
11676
11677
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11678 {
11679 new_return(9);
11680 }
11681
11682
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11683 {
11684 new_return(9);
11685 }
11686 72 }
11687
11688
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11689 {
11690
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11691 {
11692 new_return(10);
11693 }
11694
11695
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11696 {
11697 new_return(10);
11698 }
11699
11700
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11701 {
11702 new_return(10);
11703 }
11704 72 }
11705
11706
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11707 {
11708 new_return(11);
11709 }
11710
11711
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11712 {
11713 new_return(11);
11714 }
11715
11716
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11717 {
11718 new_return(11);
11719 }
11720
11721
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11722 {
11723
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11724 {
11725
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11726 {
11727 new_return(12);
11728 }
11729
11730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11731 {
11732 new_return(12);
11733 }
11734
11735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11736 {
11737 new_return(12);
11738 }
11739 108 }
11740 36 }
11741
11742
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11743 {
11744
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11745 {
11746 new_return(13);
11747 }
11748
11749
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11750 {
11751 new_return(13);
11752 }
11753
11754
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11755 {
11756 new_return(13);
11757 }
11758 72 }
11759
11760
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11761 {
11762
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11763 {
11764 new_return(13);
11765 }
11766
11767
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11768 {
11769 new_return(13);
11770 }
11771
11772
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11773 {
11774 new_return(13);
11775 }
11776 72 }
11777
11778
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11779 {
11780 new_return(14);
11781 }
11782
11783 //{ V_HEROSPRITES >= 7
11784
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11785 {
11786
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11787 new_return(15);
11788
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11789 new_return(15);
11790
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11791 new_return(15);
11792 72 }
11793
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11794 {
11795
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11796 new_return(15);
11797
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11798 new_return(15);
11799
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11800 new_return(15);
11801 72 }
11802
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11803 {
11804
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11805 new_return(15);
11806
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11807 new_return(15);
11808
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11809 new_return(15);
11810 72 }
11811
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11812 {
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11814 new_return(15);
11815
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11816 new_return(15);
11817
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11818 new_return(15);
11819 72 }
11820
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11821 {
11822
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11823 new_return(15);
11824
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11825 new_return(15);
11826
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11827 new_return(15);
11828 72 }
11829
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11830 {
11831
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11832 new_return(15);
11833
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11834 new_return(15);
11835
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11836 new_return(15);
11837 72 }
11838
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11839 {
11840
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11841 new_return(15);
11842
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11843 new_return(15);
11844
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11845 new_return(15);
11846 72 }
11847
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11848 {
11849
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11850 new_return(15);
11851
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11852 new_return(15);
11853
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11854 new_return(15);
11855 72 }
11856
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11857 {
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11859 new_return(15);
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11861 new_return(15);
11862
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11863 new_return(15);
11864
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11865 new_return(15);
11866 72 }
11867
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11868 {
11869
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11870 new_return(15);
11871
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11872 new_return(15);
11873
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11874 new_return(15);
11875 72 }
11876
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11877 {
11878
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11879 new_return(15);
11880
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11881 new_return(15);
11882
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11883 new_return(15);
11884 72 }
11885
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11886 {
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11888 new_return(15);
11889
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11890 new_return(15);
11891
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11892 new_return(15);
11893 72 }
11894
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11895 {
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11897 new_return(15);
11898
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11899 new_return(15);
11900
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11901 new_return(15);
11902 72 }
11903
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11904 {
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11906 new_return(15);
11907
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11908 new_return(15);
11909
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11910 new_return(15);
11911 72 }
11912
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11913 {
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11915 new_return(15);
11916
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11917 new_return(15);
11918
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11919 new_return(15);
11920 72 }
11921
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11922 {
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11924 new_return(15);
11925
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11926 new_return(15);
11927
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11928 new_return(15);
11929 72 }
11930
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11931 {
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11933 new_return(15);
11934
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11935 new_return(15);
11936
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11937 new_return(15);
11938 72 }
11939
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11940 {
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11942 new_return(15);
11943
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11944 new_return(15);
11945
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11946 new_return(15);
11947 72 }
11948
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11949 {
11950
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11951 new_return(15);
11952
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11953 new_return(15);
11954
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11955 new_return(15);
11956 72 }
11957
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11958 {
11959
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11960 new_return(15);
11961
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11962 new_return(15);
11963
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11964 new_return(15);
11965 72 }
11966
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11967 {
11968
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11969 new_return(15);
11970
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11971 new_return(15);
11972
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11973 new_return(15);
11974 72 }
11975
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11976 {
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11978 new_return(15);
11979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11980 new_return(15);
11981
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11982 new_return(15);
11983 72 }
11984
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11985 {
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11987 new_return(15);
11988
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11989 new_return(15);
11990
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11991 new_return(15);
11992 72 }
11993
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11994 {
11995
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11996 new_return(15);
11997
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11998 new_return(15);
11999
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12000 new_return(15);
12001 54 }
12002
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12003 {
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
12005 new_return(16);
12006
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12007 new_return(16);
12008
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12009 new_return(16);
12010 72 }
12011
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12012 {
12013
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12014 new_return(17);
12015
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12016 new_return(17);
12017
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12018 new_return(17);
12019 72 }
12020
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12021 {
12022
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12023 new_return(17);
12024
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12025 new_return(17);
12026
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12027 new_return(17);
12028 72 }
12029
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12030 {
12031
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12032 new_return(17);
12033
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12034 new_return(17);
12035
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12036 new_return(17);
12037 72 }
12038
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12039 {
12040
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12041 new_return(18);
12042
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12043 new_return(18);
12044
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12045 new_return(18);
12046 72 }
12047
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12048 {
12049
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12050 new_return(19);
12051 72 }
12052
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12053 {
12054
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12055 new_return(20);
12056
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12057 new_return(20);
12058
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12059 new_return(20);
12060 54 }
12061
12062
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12063 {
12064 new_return(21);
12065 }
12066
12067
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12068 {
12069 new_return(21);
12070 }
12071
12072
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12073 {
12074 new_return(21);
12075 }
12076
12077
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12078 {
12079
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12080 new_return(22);
12081
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12082 new_return(22);
12083
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12084 new_return(22);
12085 72 }
12086
12087
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12088 {
12089
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12090 {
12091 new_return(23);
12092 }
12093
12094
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12095 {
12096 new_return(23);
12097 }
12098
12099
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12100 {
12101 new_return(23);
12102 }
12103 72 }
12104
12105
12106
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12107 {
12108
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defence[q], f))
12109 new_return(15);
12110 2628 }
12111 //}
12112
12113
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12114 {
12115 9 section_size=writesize;
12116 9 }
12117 18 }
12118
12119 //More data will come here
12120
12121
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12122 {
12123 char ebuf[80];
12124 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12125 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12126 }
12127
12128 9 new_return(0);
12129 }
12130
12131 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12132 {
12133 9 dword section_id=ID_SUBSCREEN;
12134 9 dword section_version=V_SUBSCREEN;
12135 9 dword section_size=0;
12136
12137 //section id
12138
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12139 {
12140 new_return(1);
12141 }
12142
12143 //section version info
12144
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12145 {
12146 new_return(2);
12147 }
12148
12149
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12150 {
12151 new_return(3);
12152 }
12153
12154
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12155 {
12156 18 fake_pack_writing=(writecycle==0);
12157
12158 //section size
12159
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12160 {
12161 new_return(4);
12162 }
12163
12164 18 writesize=0;
12165
12166 18 byte sz = subscreens_active.size();
12167
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12168 new_return(5);
12169
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12170 {
12171 86 int32_t ret = subscreens_active[i].write(f);
12172 86 fake_pack_writing=(writecycle==0);
12173
12174
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12175 new_return(ret);
12176 86 }
12177
12178 18 sz = subscreens_passive.size();
12179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12180 new_return(5);
12181
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12182 {
12183 64 int32_t ret = subscreens_passive[i].write(f);
12184 64 fake_pack_writing=(writecycle==0);
12185
12186
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12187 new_return(ret);
12188 64 }
12189
12190 18 sz = subscreens_overlay.size();
12191
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12192 new_return(5);
12193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12194 {
12195 int32_t ret = subscreens_overlay[i].write(f);
12196 fake_pack_writing=(writecycle==0);
12197
12198 if(ret!=0)
12199 new_return(ret);
12200 }
12201
12202
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12203 {
12204 9 section_size=writesize;
12205 9 }
12206 18 }
12207
12208
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12209 {
12210 char ebuf[80];
12211 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12212 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12213 }
12214
12215 9 new_return(0);
12216 9 }
12217
12218 extern script_data *ffscripts[NUMSCRIPTFFC];
12219 extern script_data *itemscripts[NUMSCRIPTITEM];
12220 extern script_data *guyscripts[NUMSCRIPTGUYS];
12221 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12222 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12223 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12224 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12225 extern script_data *playerscripts[NUMSCRIPTHERO];
12226 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12227 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12228 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12229 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12230 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12231
12232 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12233 {
12234
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12235 3 return writeffscript_old(f, Header);
12236
12237 6 dword section_id = ID_FFSCRIPT;
12238 6 dword section_version = V_FFSCRIPT;
12239 6 dword section_size = 0;
12240 6 dword zasmmeta_version = METADATA_V;
12241 6 byte numscripts = 0;
12242 6 numscripts = numscripts; //to avoid unused variables warnings
12243
12244 //section id
12245
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12246 {
12247 new_return(1);
12248 }
12249
12250 //section version info
12251
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12252 {
12253 new_return(2);
12254 }
12255
12256
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12257 {
12258 new_return(3);
12259 }
12260
12261
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12262 {
12263 new_return(4);
12264 }
12265
12266
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12267 {
12268 12 fake_pack_writing=(writecycle==0);
12269
12270 //section size
12271
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12272 {
12273 new_return(5);
12274 }
12275
12276 12 writesize=0;
12277
12278 12 write_quest_zasm(f);
12279
12280
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12281 {
12282 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12283
12284
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12285 {
12286 new_return(ret);
12287 }
12288 6144 }
12289
12290
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12291 {
12292 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12293
12294
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12295 {
12296 new_return(ret);
12297 }
12298 3072 }
12299
12300
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12301 {
12302 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12303
12304
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12305 {
12306 new_return(ret);
12307 }
12308 3072 }
12309
12310
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12311
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12312 {
12313 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12314
12315
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12316 {
12317 new_return(ret);
12318 }
12319 3072 }
12320
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12321
12322
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12323 {
12324 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12325
12326
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12327 {
12328 new_return(ret);
12329 }
12330 3072 }
12331
12332
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12333 {
12334 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12335
12336
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12337 {
12338 new_return(ret);
12339 }
12340 96 }
12341
12342
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12343 {
12344 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12345
12346
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12347 {
12348 new_return(ret);
12349 }
12350 60 }
12351
12352
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12353 {
12354 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12355
12356
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12357 {
12358 new_return(ret);
12359 }
12360 3072 }
12361
12362
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12363 {
12364 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12365
12366
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12367 {
12368 new_return(ret);
12369 }
12370 3072 }
12371
12372
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12373 {
12374 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12375
12376
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12377 {
12378 new_return(ret);
12379 }
12380 3072 }
12381
12382
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12383 {
12384 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12385
12386
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12387 {
12388 new_return(ret);
12389 }
12390 3072 }
12391
12392
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12393 {
12394 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12395
12396
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12397 {
12398 new_return(ret);
12399 }
12400 6144 }
12401
12402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12403 {
12404 new_return(2000);
12405 }
12406
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12407 {
12408 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12409
12410
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12411 {
12412 new_return(ret);
12413 }
12414 6144 }
12415
12416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12417 {
12418 new_return(2001);
12419 }
12420
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12421 {
12422 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12423
12424
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12425 {
12426 new_return(ret);
12427 }
12428 3072 }
12429
12430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12431 {
12432 new_return(2001);
12433 }
12434
12435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12436 {
12437 new_return(2002);
12438 }
12439
12440 12 word numffcbindings=0;
12441
12442
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12443 {
12444
2/2
✓ Branch 0 taken 5984 times.
✓ Branch 1 taken 148 times.
6132 if(it->second.scriptname != "")
12445 {
12446 148 numffcbindings++;
12447 148 }
12448 6132 }
12449
12450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12451 {
12452 new_return(2003);
12453 }
12454
12455
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12456 {
12457
2/2
✓ Branch 0 taken 5984 times.
✓ Branch 1 taken 148 times.
6132 if(it->second.scriptname != "")
12458 {
12459
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if(!p_iputw(it->first,f))
12460 {
12461 new_return(2004);
12462 }
12463
12464
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12465 {
12466 new_return(2005);
12467 }
12468
12469
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12470 {
12471 new_return(2006);
12472 }
12473 148 }
12474 6132 }
12475
12476 12 word numglobalbindings=0;
12477
12478
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12479 {
12480
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12481 {
12482 22 numglobalbindings++;
12483 22 }
12484 96 }
12485
12486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12487 {
12488 new_return(2007);
12489 }
12490
12491
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12492 {
12493
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12494 {
12495
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12496 {
12497 new_return(2008);
12498 }
12499
12500
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12501 {
12502 new_return(2009);
12503 }
12504
12505
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12506 {
12507 new_return(2010);
12508 }
12509 22 }
12510 96 }
12511
12512 12 word numitembindings=0;
12513
12514
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12515 {
12516
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12517 {
12518 26 numitembindings++;
12519 26 }
12520 3060 }
12521
12522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12523 {
12524 new_return(2011);
12525 }
12526
12527
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12528 {
12529
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12530 {
12531
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12532 {
12533 new_return(2012);
12534 }
12535
12536
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12537 {
12538 new_return(2013);
12539 }
12540
12541
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12542 {
12543 new_return(2014);
12544 }
12545 26 }
12546 3060 }
12547
12548 //new script types
12549 //npc scripts
12550 12 word numnpcbindings=0;
12551
12552
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12553 {
12554
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12555 {
12556 numnpcbindings++;
12557 }
12558 3060 }
12559
12560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12561 {
12562 new_return(2015);
12563 }
12564
12565
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12566 {
12567
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12568 {
12569 if(!p_iputw(it->first,f))
12570 {
12571 new_return(2016);
12572 }
12573
12574 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12575 {
12576 new_return(2017);
12577 }
12578
12579 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12580 {
12581 new_return(2018);
12582 }
12583 }
12584 3060 }
12585
12586 //lweapon
12587
12588 12 word numlwpnbindings=0;
12589
12590
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12591 {
12592
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12593 {
12594 2 numlwpnbindings++;
12595 2 }
12596 3060 }
12597
12598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12599 {
12600 new_return(2019);
12601 }
12602
12603
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12604 {
12605
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12606 {
12607
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12608 {
12609 new_return(2020);
12610 }
12611
12612
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12613 {
12614 new_return(2021);
12615 }
12616
12617
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12618 {
12619 new_return(2022);
12620 }
12621 2 }
12622 3060 }
12623
12624 //////
12625
12626 //eweapon
12627
12628
12629 12 word numewpnbindings=0;
12630
12631
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12632 {
12633
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12634 {
12635 numewpnbindings++;
12636 }
12637 3060 }
12638
12639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12640 {
12641 new_return(2023);
12642 }
12643
12644
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12645 {
12646
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12647 {
12648 if(!p_iputw(it->first,f))
12649 {
12650 new_return(2024);
12651 }
12652
12653 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12654 {
12655 new_return(2025);
12656 }
12657
12658 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12659 {
12660 new_return(2026);
12661 }
12662 }
12663 3060 }
12664
12665 //player scripts
12666 12 word numherobindings=0;
12667
12668
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12669 {
12670
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12671 {
12672 numherobindings++;
12673 }
12674 48 }
12675
12676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12677 {
12678 new_return(2027);
12679 }
12680
12681
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12682 {
12683
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12684 {
12685 if(!p_iputw(it->first,f))
12686 {
12687 new_return(2028);
12688 }
12689
12690 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12691 {
12692 new_return(2029);
12693 }
12694
12695 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12696 {
12697 new_return(2030);
12698 }
12699 }
12700 48 }
12701
12702 //dmap scripts
12703 12 word numdmapbindings=0;
12704
12705
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12706 {
12707
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12708 {
12709 10 numdmapbindings++;
12710 10 }
12711 3060 }
12712
12713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12714 {
12715 new_return(2031);
12716 }
12717
12718
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12719 {
12720
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12721 {
12722
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12723 {
12724 new_return(2032);
12725 }
12726
12727
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12728 {
12729 new_return(2033);
12730 }
12731
12732
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12733 {
12734 new_return(2034);
12735 }
12736 10 }
12737 3060 }
12738
12739 //screen scripts
12740 12 word numscreenbindings=0;
12741
12742
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12743 {
12744
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12745 {
12746 4 numscreenbindings++;
12747 4 }
12748 3060 }
12749
12750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12751 {
12752 new_return(2035);
12753 }
12754
12755
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12756 {
12757
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12758 {
12759
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12760 {
12761 new_return(2036);
12762 }
12763
12764
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12765 {
12766 new_return(2037);
12767 }
12768
12769
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12770 {
12771 new_return(2038);
12772 }
12773 4 }
12774 3060 }
12775 //item sprite scripts
12776 12 word numitemspritebindings=0;
12777
12778
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12779 {
12780
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12781 {
12782 numitemspritebindings++;
12783 }
12784 3060 }
12785
12786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12787 {
12788 new_return(2039);
12789 }
12790
12791
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12792 {
12793
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12794 {
12795 if(!p_iputw(it->first,f))
12796 {
12797 new_return(2040);
12798 }
12799
12800 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12801 {
12802 new_return(2041);
12803 }
12804
12805 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12806 {
12807 new_return(2042);
12808 }
12809 }
12810 3060 }
12811
12812 //combo scripts
12813 12 word numcombobindings=0;
12814
12815
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12816 {
12817
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12818 {
12819 numcombobindings++;
12820 }
12821 6132 }
12822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12823 {
12824 new_return(2043);
12825 }
12826
12827
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12828 {
12829
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12830 {
12831 if(!p_iputw(it->first,f))
12832 {
12833 new_return(2044);
12834 }
12835
12836 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12837 {
12838 new_return(2045);
12839 }
12840
12841 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12842 {
12843 new_return(2046);
12844 }
12845 }
12846 6132 }
12847 //subscreen scripts
12848 12 word numgenericbindings=0;
12849
12850
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12851 {
12852
2/2
✓ Branch 0 taken 6102 times.
✓ Branch 1 taken 30 times.
6132 if(it->second.scriptname != "")
12853 {
12854 30 numgenericbindings++;
12855 30 }
12856 6132 }
12857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12858 {
12859 new_return(2043);
12860 }
12861
12862
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12863 {
12864
2/2
✓ Branch 0 taken 6102 times.
✓ Branch 1 taken 30 times.
6132 if(it->second.scriptname != "")
12865 {
12866
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_iputw(it->first,f))
12867 {
12868 new_return(2044);
12869 }
12870
12871
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12872 {
12873 new_return(2045);
12874 }
12875
12876
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12877 {
12878 new_return(2046);
12879 }
12880 30 }
12881 6132 }
12882
12883 //generic scripts
12884 12 word numsubscreenbindings=0;
12885
12886
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12887 {
12888
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12889 {
12890 numsubscreenbindings++;
12891 }
12892 3060 }
12893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12894 {
12895 new_return(2047);
12896 }
12897
12898
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12899 {
12900
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12901 {
12902 if(!p_iputw(it->first,f))
12903 {
12904 new_return(2048);
12905 }
12906
12907 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12908 {
12909 new_return(2049);
12910 }
12911
12912 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12913 {
12914 new_return(2050);
12915 }
12916 }
12917 3060 }
12918
12919
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12920 {
12921 6 section_size=writesize;
12922 6 }
12923 12 }
12924
12925
12926
12927
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12928 {
12929 char ebuf[80];
12930 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12931 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12932 }
12933
12934 6 new_return(0);
12935 //return 0; //this is just here to stomp the compiler from whining.
12936 //the irony is that it causes an "unreachable code" warning.
12937 9 }
12938
12939 12 int32_t write_quest_zasm(PACKFILE *f)
12940 {
12941 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12942 12 auto& zasm = zasm_scripts[0]->zasm;
12943 12 size_t num_commands = zasm.size();
12944
12945
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12946 new_return(1);
12947
12948
2/2
✓ Branch 0 taken 342600 times.
✓ Branch 1 taken 12 times.
342612 for(int32_t j=0; j<num_commands; j++)
12949 {
12950 342600 auto& zas = zasm[j];
12951
12952
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 342600 times.
342600 if(zas.command==0xFFFF)
12953 continue;
12954 else
12955 {
12956
1/2
✓ Branch 0 taken 342600 times.
✗ Branch 1 not taken.
342600 if(!p_iputw(zas.command,f))
12957 new_return(2);
12958
12959
1/2
✓ Branch 0 taken 342600 times.
✗ Branch 1 not taken.
342600 if(!p_iputl(zas.arg1,f))
12960 new_return(3);
12961
12962
1/2
✓ Branch 0 taken 342600 times.
✗ Branch 1 not taken.
342600 if(!p_iputl(zas.arg2,f))
12963 new_return(4);
12964
12965
1/2
✓ Branch 0 taken 342600 times.
✗ Branch 1 not taken.
342600 if(!p_iputl(zas.arg3,f))
12966 new_return(5);
12967
12968 342600 uint32_t sz = 0;
12969
2/2
✓ Branch 0 taken 341818 times.
✓ Branch 1 taken 782 times.
342600 if(zas.strptr)
12970 782 sz = zas.strptr->size();
12971
1/2
✓ Branch 0 taken 342600 times.
✗ Branch 1 not taken.
342600 if(!p_iputl(sz,f))
12972 new_return(6);
12973
2/2
✓ Branch 0 taken 341824 times.
✓ Branch 1 taken 776 times.
342600 if(sz)
12974 {
12975 776 auto& str = *zas.strptr;
12976
2/2
✓ Branch 0 taken 15852 times.
✓ Branch 1 taken 776 times.
16628 for(size_t q = 0; q < sz; ++q)
12977 {
12978
1/2
✓ Branch 0 taken 15852 times.
✗ Branch 1 not taken.
15852 if(!p_putc(str[q],f))
12979 new_return(7);
12980 15852 }
12981 776 }
12982 342600 sz = 0;
12983
2/2
✓ Branch 0 taken 342462 times.
✓ Branch 1 taken 138 times.
342600 if(zas.vecptr)
12984 138 sz = zas.vecptr->size();
12985
1/2
✓ Branch 0 taken 342600 times.
✗ Branch 1 not taken.
342600 if(!p_iputl(sz,f))
12986 new_return(8);
12987
2/2
✓ Branch 0 taken 342462 times.
✓ Branch 1 taken 138 times.
342600 if(sz) //vector found
12988 {
12989 138 auto& vec = *zas.vecptr;
12990
2/2
✓ Branch 0 taken 654 times.
✓ Branch 1 taken 138 times.
792 for(size_t q = 0; q < sz; ++q)
12991 {
12992
1/2
✓ Branch 0 taken 654 times.
✗ Branch 1 not taken.
654 if(!p_iputl(vec[q],f))
12993 new_return(9);
12994 654 }
12995 138 }
12996 }
12997 342600 }
12998 12 return 0;
12999 }
13000
13001 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
13002 {
13003
2/2
✓ Branch 0 taken 46006 times.
✓ Branch 1 taken 230 times.
46236 if (!script->valid())
13004 {
13005
1/2
✓ Branch 0 taken 46006 times.
✗ Branch 1 not taken.
46006 if (!p_putc(0, f))
13006 new_return(-1);
13007 46006 return 0;
13008 }
13009
13010
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if (!p_putc(1, f))
13011 new_return(-1);
13012
13013 230 zasm_meta const& tmeta = script->meta;
13014
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.zasm_v,f))
13015 new_return(1);
13016
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.meta_v,f))
13017 new_return(2);
13018
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.ffscript_v,f))
13019 new_return(3);
13020
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putc((int)tmeta.script_type,f))
13021 new_return(4);
13022
13023
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(int32_t q = 0; q < 8; ++q)
13024 {
13025
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.run_idens[q],f))
13026 new_return(5);
13027 1840 }
13028
13029
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(int32_t q = 0; q < 8; ++q)
13030
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putc(tmeta.run_types[q],f))
13031 new_return(6);
13032
13033
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putc(tmeta.flags,f))
13034 new_return(7);
13035
13036
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v1,f))
13037 new_return(8);
13038
13039
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v2,f))
13040 new_return(9);
13041
13042
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v3,f))
13043 new_return(10);
13044
13045
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v4,f))
13046 new_return(11);
13047
13048
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putcstr(tmeta.script_name,f))
13049 new_return(12);
13050
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putcstr(tmeta.author,f))
13051 new_return(13);
13052
2/2
✓ Branch 0 taken 2300 times.
✓ Branch 1 taken 230 times.
2530 for(auto q = 0; q < 10; ++q)
13053 {
13054
1/2
✓ Branch 0 taken 2300 times.
✗ Branch 1 not taken.
2300 if(!p_putcstr(tmeta.attributes[q],f))
13055 new_return(14);
13056
1/2
✓ Branch 0 taken 2300 times.
✗ Branch 1 not taken.
2300 if(!p_putwstr(tmeta.attributes_help[q],f))
13057 new_return(15);
13058 2300 }
13059
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13060 {
13061
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.attribytes[q],f))
13062 new_return(16);
13063
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putwstr(tmeta.attribytes_help[q],f))
13064 new_return(17);
13065 1840 }
13066
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13067 {
13068
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.attrishorts[q],f))
13069 new_return(18);
13070
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13071 new_return(19);
13072 1840 }
13073
2/2
✓ Branch 0 taken 3680 times.
✓ Branch 1 taken 230 times.
3910 for(auto q = 0; q < 16; ++q)
13074 {
13075
1/2
✓ Branch 0 taken 3680 times.
✗ Branch 1 not taken.
3680 if(!p_putcstr(tmeta.usrflags[q],f))
13076 new_return(20);
13077
1/2
✓ Branch 0 taken 3680 times.
✗ Branch 1 not taken.
3680 if(!p_putwstr(tmeta.usrflags_help[q],f))
13078 new_return(21);
13079 3680 }
13080
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13081 {
13082
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.initd[q],f))
13083 new_return(22);
13084
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putwstr(tmeta.initd_help[q],f))
13085 new_return(23);
13086 1840 }
13087
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13088 {
13089
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putc(tmeta.initd_type[q],f))
13090 new_return(24);
13091 1840 }
13092
13093
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputl(script->pc, f))
13094 new_return(25);
13095
13096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 230 times.
230 if(!p_iputl(script->end_pc, f))
13097 new_return(26);
13098
13099 230 return 0;
13100 46236 }
13101
13102
13103 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13104 {
13105 3 dword section_id = ID_FFSCRIPT;
13106 3 dword section_version = 26;
13107 3 dword section_cversion = 1;
13108 3 dword section_size = 0;
13109 3 dword zasmmeta_version = 5;
13110 3 byte numscripts = 0;
13111 3 numscripts = numscripts; //to avoid unused variables warnings
13112
13113 //section id
13114
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13115 {
13116 new_return(1);
13117 }
13118
13119 //section version info
13120
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13121 {
13122 new_return(2);
13123 }
13124
13125
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13126 {
13127 new_return(3);
13128 }
13129
13130
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13131 {
13132 new_return(4);
13133 }
13134
13135
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13136 {
13137 6 fake_pack_writing=(writecycle==0);
13138
13139 //section size
13140
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13141 {
13142 new_return(5);
13143 }
13144
13145 6 writesize=0;
13146
13147
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13148 {
13149 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13150 3072 fake_pack_writing=(writecycle==0);
13151
13152
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13153 {
13154 new_return(ret);
13155 }
13156 3072 }
13157
13158
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13159 {
13160 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13161 1536 fake_pack_writing=(writecycle==0);
13162
13163
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13164 {
13165 new_return(ret);
13166 }
13167 1536 }
13168
13169
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13170 {
13171 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13172 1536 fake_pack_writing=(writecycle==0);
13173
13174
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13175 {
13176 new_return(ret);
13177 }
13178 1536 }
13179
13180
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13181
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13182 {
13183 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13184 1536 fake_pack_writing=(writecycle==0);
13185
13186
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13187 {
13188 new_return(ret);
13189 }
13190 1536 }
13191
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13192
13193
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13194 {
13195 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13196 1536 fake_pack_writing=(writecycle==0);
13197
13198
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13199 {
13200 new_return(ret);
13201 }
13202 1536 }
13203
13204
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13205 {
13206 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13207 48 fake_pack_writing=(writecycle==0);
13208
13209
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13210 {
13211 new_return(ret);
13212 }
13213 48 }
13214
13215
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13216 {
13217 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13218 30 fake_pack_writing=(writecycle==0);
13219
13220
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13221 {
13222 new_return(ret);
13223 }
13224 30 }
13225
13226
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13227 {
13228 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13229 1536 fake_pack_writing=(writecycle==0);
13230
13231
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13232 {
13233 new_return(ret);
13234 }
13235 1536 }
13236
13237
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13238 {
13239 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13240 1536 fake_pack_writing=(writecycle==0);
13241
13242
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13243 {
13244 new_return(ret);
13245 }
13246 1536 }
13247
13248
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13249 {
13250 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13251 1536 fake_pack_writing=(writecycle==0);
13252
13253
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13254 {
13255 new_return(ret);
13256 }
13257 1536 }
13258
13259
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13260 {
13261 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13262 1536 fake_pack_writing=(writecycle==0);
13263
13264
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13265 {
13266 new_return(ret);
13267 }
13268 1536 }
13269
13270
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13271 {
13272 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13273 3072 fake_pack_writing=(writecycle==0);
13274
13275
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13276 {
13277 new_return(ret);
13278 }
13279 3072 }
13280
13281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13282 {
13283 new_return(2000);
13284 }
13285
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13286 {
13287 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13288 3072 fake_pack_writing=(writecycle==0);
13289
13290
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13291 {
13292 new_return(ret);
13293 }
13294 3072 }
13295
13296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13297 {
13298 new_return(2001);
13299 }
13300
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13301 {
13302 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13303 1536 fake_pack_writing=(writecycle==0);
13304
13305
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13306 {
13307 new_return(ret);
13308 }
13309 1536 }
13310
13311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13312 {
13313 new_return(2001);
13314 }
13315
13316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13317 {
13318 new_return(2002);
13319 }
13320
13321 6 word numffcbindings=0;
13322
13323
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13324 {
13325
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13326 {
13327 206 numffcbindings++;
13328 206 }
13329 3066 }
13330
13331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13332 {
13333 new_return(2003);
13334 }
13335
13336
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13337 {
13338
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13339 {
13340
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13341 {
13342 new_return(2004);
13343 }
13344
13345
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13346 {
13347 new_return(2005);
13348 }
13349
13350
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13351 {
13352 new_return(2006);
13353 }
13354 206 }
13355 3066 }
13356
13357 6 word numglobalbindings=0;
13358
13359
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13360 {
13361
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13362 {
13363 18 numglobalbindings++;
13364 18 }
13365 48 }
13366
13367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13368 {
13369 new_return(2007);
13370 }
13371
13372
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13373 {
13374
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13375 {
13376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13377 {
13378 new_return(2008);
13379 }
13380
13381
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13382 {
13383 new_return(2009);
13384 }
13385
13386
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13387 {
13388 new_return(2010);
13389 }
13390 18 }
13391 48 }
13392
13393 6 word numitembindings=0;
13394
13395
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13396 {
13397
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13398 {
13399 18 numitembindings++;
13400 18 }
13401 1530 }
13402
13403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13404 {
13405 new_return(2011);
13406 }
13407
13408
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13409 {
13410
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13411 {
13412
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13413 {
13414 new_return(2012);
13415 }
13416
13417
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13418 {
13419 new_return(2013);
13420 }
13421
13422
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13423 {
13424 new_return(2014);
13425 }
13426 18 }
13427 1530 }
13428
13429 //new script types
13430 //npc scripts
13431 6 word numnpcbindings=0;
13432
13433
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13434 {
13435
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13436 {
13437 numnpcbindings++;
13438 }
13439 1530 }
13440
13441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13442 {
13443 new_return(2015);
13444 }
13445
13446
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13447 {
13448
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13449 {
13450 if(!p_iputw(it->first,f))
13451 {
13452 new_return(2016);
13453 }
13454
13455 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13456 {
13457 new_return(2017);
13458 }
13459
13460 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13461 {
13462 new_return(2018);
13463 }
13464 }
13465 1530 }
13466
13467 //lweapon
13468
13469 6 word numlwpnbindings=0;
13470
13471
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13472 {
13473
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13474 {
13475 numlwpnbindings++;
13476 }
13477 1530 }
13478
13479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13480 {
13481 new_return(2019);
13482 }
13483
13484
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13485 {
13486
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13487 {
13488 if(!p_iputw(it->first,f))
13489 {
13490 new_return(2020);
13491 }
13492
13493 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13494 {
13495 new_return(2021);
13496 }
13497
13498 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13499 {
13500 new_return(2022);
13501 }
13502 }
13503 1530 }
13504
13505 //////
13506
13507 //eweapon
13508
13509
13510 6 word numewpnbindings=0;
13511
13512
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13513 {
13514
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13515 {
13516 numewpnbindings++;
13517 }
13518 1530 }
13519
13520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13521 {
13522 new_return(2023);
13523 }
13524
13525
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13526 {
13527
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13528 {
13529 if(!p_iputw(it->first,f))
13530 {
13531 new_return(2024);
13532 }
13533
13534 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13535 {
13536 new_return(2025);
13537 }
13538
13539 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13540 {
13541 new_return(2026);
13542 }
13543 }
13544 1530 }
13545
13546 //player scripts
13547 6 word numherobindings=0;
13548
13549
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13550 {
13551
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13552 {
13553 2 numherobindings++;
13554 2 }
13555 24 }
13556
13557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13558 {
13559 new_return(2027);
13560 }
13561
13562
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13563 {
13564
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13565 {
13566
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13567 {
13568 new_return(2028);
13569 }
13570
13571
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13572 {
13573 new_return(2029);
13574 }
13575
13576
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13577 {
13578 new_return(2030);
13579 }
13580 2 }
13581 24 }
13582
13583 //dmap scripts
13584 6 word numdmapbindings=0;
13585
13586
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13587 {
13588
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13589 {
13590 numdmapbindings++;
13591 }
13592 1530 }
13593
13594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13595 {
13596 new_return(2031);
13597 }
13598
13599
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13600 {
13601
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13602 {
13603 if(!p_iputw(it->first,f))
13604 {
13605 new_return(2032);
13606 }
13607
13608 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13609 {
13610 new_return(2033);
13611 }
13612
13613 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13614 {
13615 new_return(2034);
13616 }
13617 }
13618 1530 }
13619
13620 //screen scripts
13621 6 word numscreenbindings=0;
13622
13623
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13624 {
13625
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13626 {
13627 14 numscreenbindings++;
13628 14 }
13629 1530 }
13630
13631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13632 {
13633 new_return(2035);
13634 }
13635
13636
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13637 {
13638
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13639 {
13640
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13641 {
13642 new_return(2036);
13643 }
13644
13645
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13646 {
13647 new_return(2037);
13648 }
13649
13650
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13651 {
13652 new_return(2038);
13653 }
13654 14 }
13655 1530 }
13656 //item sprite scripts
13657 6 word numitemspritebindings=0;
13658
13659
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13660 {
13661
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13662 {
13663 numitemspritebindings++;
13664 }
13665 1530 }
13666
13667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13668 {
13669 new_return(2039);
13670 }
13671
13672
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13673 {
13674
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13675 {
13676 if(!p_iputw(it->first,f))
13677 {
13678 new_return(2040);
13679 }
13680
13681 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13682 {
13683 new_return(2041);
13684 }
13685
13686 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13687 {
13688 new_return(2042);
13689 }
13690 }
13691 1530 }
13692
13693 //combo scripts
13694 6 word numcombobindings=0;
13695
13696
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13697 {
13698
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13699 {
13700 numcombobindings++;
13701 }
13702 3066 }
13703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13704 {
13705 new_return(2043);
13706 }
13707
13708
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13709 {
13710
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13711 {
13712 if(!p_iputw(it->first,f))
13713 {
13714 new_return(2044);
13715 }
13716
13717 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13718 {
13719 new_return(2045);
13720 }
13721
13722 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13723 {
13724 new_return(2046);
13725 }
13726 }
13727 3066 }
13728 //subscreen scripts
13729 6 word numgenericbindings=0;
13730
13731
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13732 {
13733
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13734 {
13735 numgenericbindings++;
13736 }
13737 3066 }
13738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13739 {
13740 new_return(2043);
13741 }
13742
13743
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13744 {
13745
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13746 {
13747 if(!p_iputw(it->first,f))
13748 {
13749 new_return(2044);
13750 }
13751
13752 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13753 {
13754 new_return(2045);
13755 }
13756
13757 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13758 {
13759 new_return(2046);
13760 }
13761 }
13762 3066 }
13763
13764 //generic scripts
13765 6 word numsubscreenbindings=0;
13766
13767
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13768 {
13769
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13770 {
13771 numsubscreenbindings++;
13772 }
13773 1530 }
13774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13775 {
13776 new_return(2047);
13777 }
13778
13779
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13780 {
13781
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13782 {
13783 if(!p_iputw(it->first,f))
13784 {
13785 new_return(2048);
13786 }
13787
13788 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13789 {
13790 new_return(2049);
13791 }
13792
13793 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13794 {
13795 new_return(2050);
13796 }
13797 }
13798 1530 }
13799
13800
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13801 {
13802 3 section_size=writesize;
13803 3 }
13804 6 }
13805
13806
13807
13808
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13809 {
13810 char ebuf[80];
13811 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13812 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13813 }
13814
13815 3 new_return(0);
13816 //return 0; //this is just here to stomp the compiler from whining.
13817 //the irony is that it causes an "unreachable code" warning.
13818 3 }
13819
13820 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13821 {
13822 //these are here to bypass compiler warnings about unused arguments
13823 23118 Header=Header;
13824 23118 i=i;
13825
13826
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13827
13828
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13829 {
13830 new_return(6);
13831 }
13832
13833 //Metadata
13834 23118 zasm_meta const& tmeta = script->meta;
13835
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13836 {
13837 new_return(7);
13838 }
13839
13840
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13841 {
13842 new_return(8);
13843 }
13844
13845
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13846 {
13847 new_return(9);
13848 }
13849
13850
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13851 {
13852 new_return(10);
13853 }
13854
13855
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13856 {
13857
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13858 new_return(11);
13859 184944 }
13860
13861
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13862 {
13863
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13864 {
13865 new_return(12);
13866 }
13867 184944 }
13868
13869
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13870 {
13871 new_return(13);
13872 }
13873
13874
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13875 {
13876 new_return(14);
13877 }
13878
13879
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13880 {
13881 new_return(15);
13882 }
13883
13884
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13885 {
13886 new_return(16);
13887 }
13888
13889
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13890 {
13891 new_return(17);
13892 }
13893
13894
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13895 new_return(18);
13896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13897 new_return(19);
13898
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13899 {
13900
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13901 new_return(27);
13902
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13903 new_return(28);
13904 231180 }
13905
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13906 {
13907
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13908 new_return(29);
13909
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13910 new_return(30);
13911 184944 }
13912
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13913 {
13914
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13915 new_return(31);
13916
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13917 new_return(32);
13918 184944 }
13919
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13920 {
13921
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13922 new_return(33);
13923
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13924 new_return(34);
13925 369888 }
13926
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13927 {
13928
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13929 new_return(35);
13930
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13931 new_return(36);
13932 184944 }
13933
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13934 {
13935
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13936 new_return(37);
13937 184944 }
13938
13939
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13940 {
13941 2056888 auto& zas = script->zasm_script->zasm[j];
13942
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13943 {
13944 new_return(20);
13945 }
13946
13947
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13948 {
13949 11830 break;
13950 }
13951 else
13952 {
13953
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13954 {
13955 new_return(21);
13956 }
13957
13958
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13959 {
13960 new_return(22);
13961 }
13962
13963
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13964 {
13965 new_return(23);
13966 }
13967
13968 2045058 uint32_t sz = 0;
13969
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13970 2340 sz = zas.strptr->size();
13971
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13972 {
13973 new_return(23);
13974 }
13975
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13976 {
13977 2340 auto& str = *zas.strptr;
13978
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13979 {
13980
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13981 {
13982 new_return(24);
13983 }
13984 214720 }
13985 2340 }
13986 2045058 sz = 0;
13987
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13988 22 sz = zas.vecptr->size();
13989
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13990 {
13991 new_return(25);
13992 }
13993
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13994 {
13995 22 auto& vec = *zas.vecptr;
13996
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13997 {
13998
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13999 {
14000 new_return(26);
14001 }
14002 352 }
14003 22 }
14004 }
14005 2045058 }
14006
14007 23118 new_return(0);
14008 }
14009
14010 extern SAMPLE customsfxdata[WAV_COUNT];
14011 extern uint8_t customsfxflag[WAV_COUNT>>3];
14012
14013 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
14014 {
14015 //these are here to bypass compiler warnings about unused arguments
14016 9 Header=Header;
14017
14018 9 dword section_id=ID_SFX;
14019 9 dword section_version=V_SFX;
14020 9 dword section_size=0;
14021
14022 //section id
14023
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14024 {
14025 new_return(1);
14026 }
14027
14028 //section version info
14029
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14030 {
14031 new_return(2);
14032 }
14033
14034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14035 {
14036 new_return(3);
14037 }
14038
14039
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14040 {
14041 18 fake_pack_writing=(writecycle==0);
14042
14043 //section size
14044
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14045 {
14046 new_return(4);
14047 }
14048
14049 18 writesize=0;
14050
14051
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14052 {
14053
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14054 {
14055 new_return(5);
14056 }
14057 576 }
14058
14059
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14060 {
14061
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14062 3330 continue;
14063
14064
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14065 {
14066 new_return(5);
14067 }
14068 1260 }
14069
14070
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14071 {
14072
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14073 3330 continue;
14074
14075
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14076 {
14077 new_return(5);
14078 }
14079
14080
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14081 {
14082 new_return(6);
14083 }
14084
14085
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14086 {
14087 new_return(7);
14088 }
14089
14090
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14091 {
14092 new_return(8);
14093 }
14094
14095
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14096 {
14097 new_return(9);
14098 }
14099
14100
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14101 {
14102 new_return(10);
14103 }
14104
14105
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14106 {
14107 new_return(11);
14108 }
14109
14110
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14111 {
14112 new_return(12);
14113 }
14114
14115 //de-endianfy the data
14116 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14117
14118
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14119 {
14120
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14121 {
14122 new_return(13);
14123 }
14124 28596352 }
14125 1260 }
14126
14127
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14128 {
14129 9 section_size=writesize;
14130 9 }
14131 18 }
14132
14133
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14134 {
14135 char ebuf[80];
14136 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14137 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14138 }
14139
14140 9 new_return(0);
14141 }
14142
14143 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14144 {
14145 9 dword section_id=ID_INITDATA;
14146 9 dword section_version=V_INITDATA;
14147 9 dword section_size = 0;
14148
14149 9 zinit.last_map=Map.getCurrMap();
14150 9 zinit.last_screen=Map.getCurrScr();
14151 9 zinit.normalize();
14152
14153 //section id
14154
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14155 {
14156 new_return(1);
14157 }
14158
14159 //section version info
14160
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14161 {
14162 new_return(2);
14163 }
14164
14165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14166 {
14167 new_return(3);
14168 }
14169
14170 //TODO
14171
14172
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14173 {
14174 18 fake_pack_writing=(writecycle==0);
14175
14176 //section size
14177
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14178 new_return(4);
14179
14180 18 writesize=0;
14181
14182
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14183
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14184 new_return(5);
14185
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14186 {
14187
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(zinit.litems[q], f))
14188 new_return(6);
14189 9216 }
14190
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14191 new_return(10);
14192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14193 new_return(11);
14194
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14195
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14196 new_return(12);
14197
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14198
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14199 new_return(13);
14200
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14201 new_return(14);
14202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14203 new_return(15);
14204
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14205 new_return(16);
14206
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14207 new_return(17);
14208
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14209 new_return(18);
14210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14211 new_return(19);
14212
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14213 new_return(20);
14214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14215 new_return(21);
14216
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14217 new_return(22);
14218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14219 new_return(23);
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14221 new_return(24);
14222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14223 new_return(25);
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14225 new_return(26);
14226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14227 new_return(27);
14228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14229 new_return(28);
14230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14231 new_return(29);
14232
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14233 new_return(30);
14234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14235 new_return(31);
14236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14237 new_return(32);
14238
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14239 new_return(33);
14240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14241 new_return(34);
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14243 new_return(35);
14244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14245 new_return(36);
14246
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14247 new_return(37);
14248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14249 new_return(38);
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14251 new_return(39);
14252
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14253 new_return(40);
14254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14255 new_return(41);
14256
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14257 new_return(42);
14258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14259 new_return(43);
14260
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14261 new_return(44);
14262
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14263 new_return(45);
14264
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14265 new_return(46);
14266
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14267 new_return(47);
14268
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14269 new_return(48);
14270
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14271 new_return(49);
14272
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14273 new_return(50);
14274
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14275 new_return(51);
14276
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14277 new_return(52);
14278
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14279 new_return(53);
14280
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14281 new_return(54);
14282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14283 new_return(55);
14284
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14285 new_return(56);
14286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14287 new_return(57);
14288
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14289 new_return(58);
14290
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14291 new_return(59);
14292
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14293 new_return(60);
14294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14295 new_return(61);
14296
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14297 new_return(62);
14298
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14299 new_return(63);
14300
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14301 new_return(64);
14302
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14303 new_return(65);
14304
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14305 new_return(66);
14306
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14307 new_return(67);
14308
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14309 new_return(68);
14310
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14311 new_return(69);
14312
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14313 new_return(70);
14314
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14315 new_return(71);
14316
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14317 new_return(72);
14318
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14319 new_return(73);
14320
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14321 new_return(74);
14322
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14323 new_return(75);
14324
14325
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14326 {
14327 9 section_size=writesize;
14328 9 }
14329 18 }
14330
14331
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14332 {
14333 char ebuf[80];
14334 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14335 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14336 }
14337
14338 9 new_return(0);
14339 }
14340
14341 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14342 {
14343 //these are here to bypass compiler warnings about unused arguments
14344 9 Header=Header;
14345
14346 9 dword section_id=ID_ITEMDROPSETS;
14347 9 dword section_version=V_ITEMDROPSETS;
14348 // dword section_size=0;
14349 9 dword section_size = 0;
14350 9 word num_item_drop_sets=count_item_drop_sets();
14351
14352 //section id
14353
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14354 {
14355 new_return(1);
14356 }
14357
14358 //section version info
14359
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14360 {
14361 new_return(2);
14362 }
14363
14364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14365 {
14366 new_return(3);
14367 }
14368
14369
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14370 {
14371 18 fake_pack_writing=(writecycle==0);
14372
14373 //section size
14374
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14375 {
14376 new_return(4);
14377 }
14378
14379 18 writesize=0;
14380
14381 //finally... section data
14382
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14383 {
14384 new_return(5);
14385 }
14386
14387
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14388 {
14389
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14390 {
14391 new_return(6);
14392 }
14393
14394
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14395 {
14396
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14397 {
14398 new_return(7);
14399 }
14400 2360 }
14401
14402
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14403 {
14404
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14405 {
14406 new_return(8);
14407 }
14408 2596 }
14409 236 }
14410
14411
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14412 {
14413 9 section_size=writesize;
14414 9 }
14415 18 }
14416
14417
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14418 {
14419 char ebuf[80];
14420 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14421 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14422 }
14423
14424 9 new_return(0);
14425 }
14426
14427 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14428 {
14429 9 dword section_id=ID_FAVORITES;
14430 9 dword section_version=V_FAVORITES;
14431 9 dword section_size = 0;
14432
14433 //section id
14434
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14435 {
14436 new_return(1);
14437 }
14438
14439 //section version info
14440
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14441 {
14442 new_return(2);
14443 }
14444
14445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14446 {
14447 new_return(3);
14448 }
14449
14450
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14451 {
14452 18 fake_pack_writing=(writecycle==0);
14453
14454 //section size
14455
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14456 new_return(4);
14457
14458 18 writesize=0;
14459
14460
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14461 new_return(16);
14462
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14463 new_return(17);
14464
14465 18 word favcmb_cnt = 0;
14466
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14467
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14468 {
14469 14 favcmb_cnt = q+1;
14470 14 break;
14471 }
14472
14473
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14474 new_return(5);
14475
14476
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14477 {
14478
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14479 new_return(6);
14480
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14481 new_return(7);
14482 460 }
14483
14484
14485 18 word max_combo_cols = MAX_COMBO_COLS;
14486
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14487 new_return(9);
14488
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14489 {
14490
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14491 new_return(10);
14492
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14493 new_return(11);
14494
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14495 new_return(12);
14496 72 }
14497 18 word max_mappages = MAX_MAPPAGE_BTNS;
14498
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14499 new_return(13);
14500
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14501 {
14502
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14503 new_return(14);
14504
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14505 new_return(15);
14506 162 }
14507
14508
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14509 {
14510 9 section_size=writesize;
14511 9 }
14512 18 }
14513
14514
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14515 {
14516 char ebuf[80];
14517 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14518 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14519 }
14520
14521 9 new_return(0);
14522 }
14523
14524 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14525 {
14526
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14527 9 reset_combo_animations();
14528 9 reset_combo_animations2();
14529 9 strcpy(header.id_str,QH_NEWIDSTR);
14530 9 header.zelda_version = ZELDA_VERSION;
14531 9 header.internal = INTERNAL_VERSION;
14532 9 header.data_flags[ZQ_TILES] = true;
14533 9 header.data_flags[ZQ_CHEATS2] = 1;
14534 9 header.build=VERSION_BUILD;
14535
14536
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14537 {
14538 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14539 2268 }
14540
14541 char zinfofilename[2048];
14542 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14543
14544 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14545 9 box_out("Saving Quest...");
14546 9 box_eol();
14547 9 box_eol();
14548
14549
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14550
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14551
14552
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14553 return 1;
14554
14555
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14556
14557
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14558 return 2;
14559
14560
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14561
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14562
14563
14564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14565 {
14566 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14567
14568 box_out("Writing ZInfo...");
14569 if(inf)
14570 {
14571 if(writezinfo(inf,ZI)!=0)
14572 return 2;
14573
14574 pack_fclose(inf);
14575 box_out("okay.");
14576 }
14577 else box_out(" ...file failure");
14578 box_eol();
14579 }
14580 else
14581 {
14582
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14583
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14584 return 2;
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14586
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14587 }
14588
14589
14590
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14591
14592
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14593 return 3;
14594
14595
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14596
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14597
14598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14599
14600
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14601 return 4;
14602
14603
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14604
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14605
14606
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14607
14608
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14609 return 5;
14610
14611
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14612
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14613
14614
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14615
14616
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14617 return 6;
14618
14619
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14620
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14621
14622
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14623
14624
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14625 return 7;
14626
14627
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14628
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14629
14630
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14631
14632
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14633 return 8;
14634
14635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14636
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14637
14638
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14639
14640
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14641 return 9;
14642
14643
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14644
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14645
14646
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14647
14648
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14649 return 10;
14650
14651
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14652
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14653
14654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14655
14656
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14657 return 11;
14658
14659
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14660
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14661
14662
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14663
14664
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14665 return 12;
14666
14667
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14668
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14669
14670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14671
14672
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14673 return 13;
14674
14675
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14676
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14677
14678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14679
14680
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14681 return 14;
14682
14683
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14684
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14685
14686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14687
14688
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14689 return 15;
14690
14691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14693
14694
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14695
14696
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14697 return 16;
14698
14699
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14700
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14701
14702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14703
14704
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14705 return 17;
14706
14707
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14708
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14709
14710
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14711
14712
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14713 return 18;
14714
14715
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14716
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14717
14718
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14719
14720
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14721 return 19;
14722
14723
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14725
14726
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14727
14728
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14729 return 20;
14730
14731
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14732
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14733
14734
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14735
14736
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14737 return 21;
14738
14739
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14740
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14741
14742
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14743
14744
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14745 return 22;
14746
14747
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14748
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14749
14750
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14751
14752
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14753 return 23;
14754
14755
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14756
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14757
14758
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14759
14760
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14761 return 24;
14762
14763
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14764
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14765
14766
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14767
14768
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14769 return 25;
14770
14771
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14772
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14773
14774
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14775
14776
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14777 return 26;
14778
14779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14780
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14781
14782
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14783
14784
14785
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14786 {
14787 char const* kfname = filename;
14788 char keyfilename[2048]={0};
14789 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14790
14791 char temp_pw[QSTPWD_LEN] = {0};
14792 uint ind = 0;
14793 for(char const* ext : {"key","zpwd","zcheat"})
14794 {
14795 replace_extension(keyfilename, kfname, ext, 2047);
14796 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14797 char msg[80] = {0};
14798 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14799 msg[78]=13;
14800 msg[79]=10;
14801 pfwrite(msg, 80, fp);
14802 p_iputw(header.zelda_version,fp);
14803 p_putc(header.build,fp);
14804 char const* pwd = header.password;
14805 if(ind == 2) //.zcheat, hashed pwd
14806 {
14807 char hashmap = 'Z';
14808 hashmap += 'Q';
14809 hashmap += 'U';
14810 hashmap += 'E';
14811 hashmap += 'S';
14812 hashmap += 'T';
14813 for ( int q = 0; q < QSTPWD_LEN; ++q )
14814 {
14815 temp_pw[q] = header.password[q];
14816 temp_pw[q] += hashmap;
14817 }
14818 pwd = temp_pw;
14819 }
14820 pfwrite(pwd, strlen(pwd), fp);
14821 pack_fclose(fp);
14822 ++ind;
14823 }
14824 }
14825
14826 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14827 9 std::error_code ec;
14828
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14830 {
14831 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14832 return ec.value();
14833 }
14834
14835
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14836
14837 #ifdef __EMSCRIPTEN__
14838 em_sync_fs();
14839 #endif
14840
14841 9 return 0;
14842 9 }
14843
14844 // #ifdef _WIN32
14845 // static std::time_t to_time_t(FILETIME const& ft) {
14846 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14847 // t -= 116444736000000000ull;
14848 // t /= 10000000u;
14849 // return static_cast<std::time_t>(t);
14850 // }
14851 // #else
14852 // #endif
14853 template<typename TP>
14854 6 static std::time_t to_time_t(TP tp) {
14855 using namespace std::chrono;
14856 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14857 6 return system_clock::to_time_t(sctp);
14858 }
14859
14860 6 std::string get_time_last_modified_string(std::string path)
14861 {
14862
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14863 // TODO: C++20 but not supported yet.
14864 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14865 6 std::time_t tt = to_time_t(write_time);
14866 6 std::tm *gmt = std::gmtime(&tt);
14867 6 std::stringstream buffer;
14868
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14869
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14870 6 return formattedFileTime;
14871
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14872
14873 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14874 {
14875 // Always backup quest if it was last saved in a different version of the editor,
14876 // or if this a new file and is overwritting another qst file.
14877
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14878 {
14879 6 std::string backup_name;
14880
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14881
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14882 {
14883
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14884 6 }
14885 else
14886 {
14887 backup_name = fmt::format("{}", last_mod);
14888 }
14889
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14890
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14891
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14892 {
14893
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14894
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14895 {
14896
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14897 6 }
14898 else
14899 {
14900 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14901 }
14902 6 }
14903 6 }
14904
14905 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14906 9 fake_pack_writing = false;
14907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14908 {
14909 box_out("-- Error saving quest file! --");
14910 box_end(true);
14911 }
14912 9 else box_end(false);
14913 9 return ret;
14914 }
14915
14916 9 int32_t save_quest(const char *filename, bool timed_save)
14917 {
14918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14919
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14920 char ext1[5];
14921 9 ext1[0]=0;
14922
14923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14924 {
14925 sprintf(ext1, "qt");
14926 }
14927 else
14928 {
14929 9 sprintf(ext1, "qb");
14930 }
14931
14932
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14933 {
14934 char backupname[2048];
14935 char backupname2[2048];
14936 char ext[12];
14937
14938 for(int32_t i=retention-1; i>0; --i)
14939 {
14940 sprintf(ext, "%s%d", ext1, i-1);
14941 replace_extension(backupname, filepath, ext, 2047);
14942
14943 if(exists(backupname))
14944 {
14945 sprintf(ext, "%s%d", ext1, i);
14946 replace_extension(backupname2, filepath, ext, 2047);
14947
14948 if(exists(backupname2))
14949 {
14950 remove(backupname2);
14951 }
14952
14953 rename(backupname, backupname2);
14954 }
14955 }
14956
14957 //don't do this if we're not saving to the same name -DD
14958 if(!timed_save && !strcmp(filepath, filename))
14959 {
14960 sprintf(ext, "%s%d", ext1, 0);
14961 replace_extension(backupname, filepath, ext, 2047);
14962 rename(filepath, backupname);
14963 }
14964 }
14965
14966 int32_t ret;
14967 9 ret = save_unencoded_quest(filename, compress, filename);
14968
14969 9 return ret;
14970 }
14971
14972 8 void center_zq_class_dialogs()
14973 {
14974 8 jwin_center_dialog(pwd_dlg);
14975 8 }
14976
14977 void zmap::prv_secrets(bool high16only)
14978 {
14979 mapscr *s = &prvscr;
14980 mapscr *t = prvlayers;
14981 int32_t ft=0;
14982
14983 for(int32_t i=0; i<176; i++)
14984 {
14985 if(!high16only)
14986 {
14987 for(int32_t j=-1; j<6; j++)
14988 {
14989 int32_t newflag = -1;
14990
14991 for(int32_t iter=0; iter<2; ++iter)
14992 {
14993 if(!t[j].valid)
14994 continue;
14995
14996 int32_t checkflag=combobuf[t[j].data[i]].flag;
14997
14998 if(iter==1)
14999 {
15000 checkflag=t[j].sflag[i];
15001 }
15002
15003 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15004 if (ft != -1)
15005 {
15006 if(j==-1)
15007 {
15008 s->data[i] = s->secretcombo[ft];
15009 s->cset[i] = s->secretcset[ft];
15010 newflag = s->secretflag[ft];
15011 }
15012 else
15013 {
15014 t[j].data[i] = t[j].secretcombo[ft];
15015 t[j].cset[i] = t[j].secretcset[ft];
15016 newflag = t[j].secretflag[ft];
15017 }
15018 }
15019 }
15020
15021 if(newflag >-1)
15022 {
15023 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15024 }
15025 }
15026 }
15027
15028 //if(true)
15029 //{
15030 int32_t newflag = -1;
15031
15032 for(int32_t iter=0; iter<2; ++iter)
15033 {
15034 int32_t checkflag=combobuf[s->data[i]].flag;
15035
15036 if(iter==1)
15037 {
15038 checkflag=s->sflag[i];
15039 }
15040
15041 if((checkflag > 15)&&(checkflag < 32))
15042 {
15043 s->data[i] = s->secretcombo[(checkflag)-16+4];
15044 s->cset[i] = s->secretcset[(checkflag)-16+4];
15045 newflag = s->secretflag[(checkflag)-16+4];
15046 // putit = true;
15047 }
15048 }
15049
15050 if(newflag >-1) s->sflag[i] = newflag;
15051
15052 for(int32_t j=0; j<6; j++)
15053 {
15054 if(!t[j].valid) continue;
15055
15056 int32_t newflag2 = -1;
15057
15058 for(int32_t iter=0; iter<2; ++iter)
15059 {
15060 int32_t checkflag=combobuf[t[j].data[i]].flag;
15061
15062 if(iter==1)
15063 {
15064 checkflag=t[j].sflag[i];
15065 }
15066
15067 if((checkflag > 15)&&(checkflag < 32))
15068 {
15069 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15070 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15071 newflag2 = t[j].secretflag[(checkflag)-16+4];
15072 }
15073 }
15074
15075 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15076 }
15077 }
15078
15079 //FFCs
15080 word num_ffcs = s->numFFC();
15081 for(word i=0; i<num_ffcs; ++i)
15082 {
15083 if(!high16only)
15084 {
15085 for(int32_t iter=0; iter<1; ++iter)
15086 {
15087 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15088
15089 if(iter==1)
15090 {
15091 checkflag=s->sflag[i];
15092 }
15093
15094 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15095 if (ft != -1)
15096 {
15097 s->ffcs[i].data = s->secretcombo[ft];
15098 s->ffcs[i].cset = s->secretcset[ft];
15099 }
15100 }
15101 }
15102
15103 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15104 {
15105 for(int32_t iter=0; iter<1; ++iter)
15106 {
15107 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15108
15109 if(iter==1)
15110 {
15111 // FFCs can't have flags! Yet...
15112 }
15113
15114 if((checkflag > 15)&&(checkflag < 32))
15115 {
15116 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15117 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15118 }
15119 }
15120 }
15121 }
15122 }
15123